blog.scoreman.net

Open SharePoint links in new Window using JQuery

Today a customer wanted to open some of their links in a SharePoint Links List in a new window. After some googling I found this post. It solved the problem by adding a named achor to the url and then manipulating the all hyperlinks with that anchor using JavaScript. I decieded to do this using JQuery instread.

Below is the code I wrote. Put the script in a content editor web part above the web part showing the links or incorporate it into your master page. Please change the protocol for the jquery script link depending on if you run http or https.

<script src="https://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
  $("a[href$='#openinnewwindow']").each(function() {
    $(this).attr("target", "_blank");
    $(this).attr("href", $(this).attr("href").replace(/#openinnewwindow/, ''));
  });
});
</script>

2 Responses to “Open SharePoint links in new Window using JQuery”

  1. SPAdam Says:

    Thanks! But simple and easiest solution is: Create a Site column of “Hyperlink with formatting and constraints for publishing” type and add it in your list, which enables you to specify “Open in New Window” Option!

    There are few more possible solutions, including JavaScript, JQuery, SharePoint Designer, List Schema Edit to make SharePoint Link list open in new window at SharePointDiary.com –

    SharePoint Link list: Open in a New Window

  2. Casper Says:

    I’m trying something related: I have a page with some links on it.
    They all point to the same sharepoint list but have a filter on them.
    I’m trying to get those links to open in a CEWP of Page viewer web part on the same page as the links are on but I can not for the life of me get this figured out :S

Leave a Reply