Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Open in a new window

  Asked By: Urjita    Date: Jun 08    Category: Sharepoint    Views: 2476

Is there a way to have a link open in a new window when using a Links webpart.
I'm not talking about words (links) used in text such as the Content Editor. I'm
referring to a Links part.



4 Answers Found

Answer #1    Answered By: Eashan Nadkarni     Answered On: Jun 08

I had to create a custom field type to do this - then use a custom list.

Answer #2    Answered By: William Odom     Answered On: Jun 08

There is a solution WINDOWSLINKS.WSP on Codeplex that creates a list
type of Windows link  that gives you control of the link, including tool
bars, size and new window.

Answer #3    Answered By: Mia Scott     Answered On: Jun 08

For a simple "no installation or server access required" solution, see

(This link  will get broken, so you will need to copy and paste the two halves
back together.)

Briefly, in this solution you add "#openinnewwindow" to the end of links  you
want to open  in a new window. You then add some JavaScript in a content  editor
web part  that finds those links on the page and replaces them with the correct
function to open in a new window.

Answer #4    Answered By: Kristian Chaney     Answered On: Jun 08

A correction: I tried to use the solution given in that web page, and found it
didn't work. The reason is that the JavaScript on the page has errors, probably
introduced when being copy and pasted into the web page.

Here is a corrected version of the script to be placed into a content  editor web
part (I hope it survives this copy and paste!):

<script language="JavaScript">
//add an entry to the _spBodyOnLoadFunctionNames array
//so that our function will run on the pageLoad event

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;

Didn't find what you were looking for? Find more on Open in a new window Or get search suggestion and latest updates.