Within SharePoint, you can have links to other resources outside of SharePoint. These could go to other internal systems, or external websites. Also, if you’re using Enterprise Search and index websites which are not within SharePoint the search results will include links to outside of SharePoint. The issue with linking to external sites and resources outside of SharePoint is that the link takes over the window so the user leaves SharePoint. Instead, I want the user to go to the link within a new window, thereby keeping the user in SharePoint when they’re done with other resource.
Pretty simple concept, but updating links manually throughout SharePoint might be a pain. Below is a simple little JQuery script that checks all hyperlinks on the page and if it references an external URL, it will set the target to blank! Throw this in your masterpage or in a content editor web part if you only want it on a couple of pages.
NOTE: you’ll need to include a reference to the JQuery files, below I’m using Google’s API, but I recommend uploading the JQuery file into your farm and referencing that instead.
Hi, I’m trying to get this to work for the Link to Document content types from a document library web part and it’s not working – any ideas? Thanks Much
Ah that content type is wonky, it actually creates an ASPX page and then that does the linking. Not sure there’s a way around that
Well originally i thought i was having the same issues as Ralph but now i dont think my script is firing. I am not sure what the best way is to implement this script on my list. I guess my question would be can this script execute on hyperlinks that are inside a Links Web Part? If so what would be the best way to implement it so that it does that on Hyperlinks in my list?
I have tried so many different ways and scripts, and none of them seem to work.
Did this ever get resolved? and if so what was the solution as i am having the same issue.
Which issue are you referring to exactly?
ok, let’s take this off blog, email me directly david.lozzi at slalom.com
Oh, what I was saying is your code works great for external sites in a list, seems to work no mater what… it works as you intended… I would like to have a new window for any type of link even when they are grouped..Some examples I’ve seen don’t work on a grouped list, but I don’t know why..
$(“.ms-vb a”).attr(‘target’, ‘_blank’);
This works great except as soon as I group it…The functionality is lost.
Use the dev tool bar, and enter in just $(“.ms-vb a”), do you get objects returned?
Hold on I’ll check…I keep having to refresh this page…Not seeing your answer right away…
So all these links open in a new window…I am trying to use client side tools to recreate the same thing in 2013.
Are there any JS errors in the dev tool bar? Are the A tags on the page when this code runs, are the links being loaded through an async call?
“Are the A tags on the page when this code runs”…..Your code, if that’s what you mean works fine!
Yes…This is what I had before SharePoint 2013 ..It was done with SharePoint designer 2010…I used a Dataview web part to change all the a tag’s in the webpart…
Hi David! This works great!
Sorry to be a bother, but I was wondering if you had something like this for internal and external sites and that would work on a grouped list..Some scripts I’ve tried won’t work with a grouped list..
Sorry I’m not sure I’m following. Are you talking about non-SharePoint site, desiring to do the same thing?
Both SharePoint and External…Basically anything. I am making a popup links list…That will give people a common set of links…The striped down popup window will show the list and will display on logon. So anything they click on produces a separate window.
This code is grabbing all a tags, all links. If the links are using JS to open links that me be interfering. Can you point me to an external reference?
Abu – with the hyperlink- publishing type column you lose sorting. Column head freezes. To David! – thank you for your post it was the most simple and straight to the point I’ve seen across many pages! Kudos.
This works great! I was just wondering if you had something that works for both internal and external sites, your code worked great in a grouped list, which is what I’m using.
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!
SharePoint Link list: Open in a New Window
Create the function to open your target window as sample provide below.
Click site actions, select manage content and structure.
Suppose you want to change the links in the page
Then select the List named HelpLinks in the sub site Help. Dev will be the top most node(site). Help will be a sub site and inside Help you can find List by name HelpLinks.
1. All the links in the page and their title will be displayed
2. Select the title of link which you want to open in new tab and right click.
Suppose you want to change the links in the below URL.
1. open to the link http://someserver/sites/Dev/Help/HelpLinks/AllItems.aspx
2. You will find the columns of the List (Title Column, URL column, Summary etc).
3. Select the Title and click Edit property which you want to edit