| Paul's profileAutoSpongePhotosBlogLists | Help |
|
|
July 02 Cleanup Hyperlinks in Calculated ColumnsA common request from end users: "Can we make a calculated column of hyperlinks that don't display the whole url?" Because MOSS filters "dangerous code" from metadata columns, calculated columns can not resolve to something with code in it and the Excel function "HYPERLINK" does not work in MOSS. So, what can we do? Admins and power users can clean this up with SPD or custom web parts. However, the end user has fewer options. If the end user has the Edit Page permission and access to the Content Editor Web Part, they can use some javascript to clean up the links. If you don't normally allow that, you may want to add the second technique's script to your default.master as it will clean up any ugly links on your page. Technique 1 Let's say, you have a bunch of document names in a list and you want to create a url to another site using a calculated column like this: ="http://google.com/"&Title We know the "base URL" and we want to dynamically separate the appended portion from the base (e.g., displaying http://www.google.com/labs as labs), so we add this script to the list view page using a CEWP: <script type="text/javascript"> _spBodyOnLoadFunctionNames.push("cleanLinks");
function cleanLinks(){ var baseURL = "http://google.com/"; var len = baseURL.length; var links = document.getElementsByTagName("a"); for (var i=0; i < links.length; i++) { if (links[i].href && links[i].href.substring(0,len) == baseURL){ if (links[i].innerText==undefined) { links[i].textContent = links[i].textContent.substring(len); } else{ links[i].innerText = links[i].innerText.substring(len); //for IE } } } }
//--> </script>
<script type="text/javascript"> _spBodyOnLoadFunctionNames.push("cleanLinks");
function cleanLinks(){ var links = document.getElementsByTagName("a"); for (var i=0; i < links.length; i++) { if (links[i].href && links[i].href == links[i].innerText){ links[i].innerText = "link"; }else{ if (links[i].href && links[i].href == links[i].textContent){ links[i].textContent = "link"; } } } }
//--> </script>
A slightly fancier version of that technique adds an image using some embedded CSS:
<STYLE TYPE="text/css" MEDIA=screen> <!-- .mylink { background-image: url(/_layouts/images/link.gif); background-repeat: no-repeat; font-family: tahoma,sans-serif; font-size: 8pt; padding-left: 25px; } --> </STYLE> <script type="text/javascript"> _spBodyOnLoadFunctionNames.push("cleanLinks");
function cleanLinks(){ var links = document.getElementsByTagName("a"); for (var i=0; i < links.length; i++) { if (links[i].href && links[i].href == links[i].innerText){ links[i].parentNode.className="mylink"; links[i].innerText = "link"; }else{ if (links[i].href && links[i].href == links[i].textContent){ links[i].parentNode.className="mylink"; links[i].textContent = "link"; } } } } //--> </script>
Comments (1)TrackbacksThe trackback URL for this entry is: http://autosponge.spaces.live.com/blog/cns!D7F85948C20F0293!446.trak Weblogs that reference this entry
|
|
|