fredag den 7. maj 2010

Pop Up New Window Using the Out-of-the-box Links List

SharePoint "links lists" are very handy. The only problem is that out-of-the-box, the links take over the browser window. While desirable for some navigation tasks, it is not always optimal.

Sometimes I use a Content Editor Web Part to make custom links, but these are not permission sensitive the way SharePoin Lists can be.

There is a 3rd party web part add-on called "Windows Links" for WSS3/MOSS2007 (see this article) that works just fine, but it requires an installation of the web part. This can (and probably will) cause issues during an upgrade to the next version of SharePoint.

The basic idea is that Link List is added to a Web Part Zone on a site page or web part page. Then a Content Editor Web Part is added (anywhere) onto the same page.

The code is entered into a Content Editor Web Part using the "Source Editor" (not the Rich Text Editor), as pictured below.

Copy/Paste code below:

<script language="JavaScript">
//add an entry to the _spBodyOnLoadFunctionNames array
//so that our function will run on the pageLoad event
_spBodyOnLoadFunctionNames.push("rewriteLinks");
function rewriteLinks() {
//create an array to store all the anchor elements in the page
var anchors = document.getElementsByTagName("a");
//loop through the array
for (var x=0; x<anchors.length; x++) {
//does this anchor element contain #openinnewwindow?
if (anchors[x].outerHTML.indexOf('#openinnewwindow')>0)
{
//store the HTML for this anchor element
oldText = anchors[x].outerHTML;
//rewrite the URL to remove our test text and add a target instead
newText = oldText.replace(/#openinnewwindow/,'" target="_blank');
//write the HTML back to the browser
anchors[x].outerHTML = newText;
}
}
}
</script>

The Content Editor Web Part can be hidden if desired (look in the "Layout" section of the web part options).

And finally, when creating links in the Links List, add #openinnewwindow on the end of each link that you would like to open in a new window.


 

5 kommentarer:

ek sagde ...

Thanks for sharing the information.

Data Science Course In Pune

ek sagde ...

I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon…

Data Science Course

svilas sagde ...

Just saying thanks will not just be sufficient, for the fantastic lucidity in your writing. I will instantly grab your articles to get deeper into the topic. And as the same way ExcelR also helps organisations by providing data science courses based on practical knowledge and theoretical concepts. It offers the best value in training services combined with the support of our creative staff to provide meaningful solution that suits your learning needs.

tejaswini sagde ...

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
data science course in malaysia

tejaswini sagde ...

I honestly think I was overjoyed to find the posts.https://360digitmg.com/course/certification-program-in-data-science