Home > SharePoint 2007 > Open links (PDF document) in a new window

Open links (PDF document) in a new window

A client requests that the PDFs stored in a SharePoint document library need to be opened in new window instead of navigating the page away.
Thanks to the tip from Dustin Miller (http://www.sharepointblogs.com/dustin/archive/2006/02/03/supergeek-tip-open-off-site-links-in-a-new-window.aspx), I just modify the script to suit my needs.
   var theLinks = document.links;
   var thisDomain = window.location.hostname;
   // Edit "theMessage" to your liking
   var theMessage = "You are now leaving " + thisDomain + ".  The content of the requested web site is outside our control.  The requested web page will open in a new window.  You may click \"Cancel\" to stop loading the requested page.  You may need to hold your CTRL key down when pressing \"OK\" to bypass your pop-up blocking software.";
   // Change "showMessage" to 0 if you don’t want the warning to pop up when navigating to external sites.
   var showMessage = 1;
   function updateLinks() {
  for (i=0; i < theLinks.length; i++) {
   var thisLink = theLinks[ i ]; //Note: Remove the spaces if you like
   if (thisLink.href.indexOf(thisDomain) >=0 && thisLink.href.indexOf(".pdf") >=0) {
    thisLink.target = "_blank";
    //if (showMessage == 1) {
     //thisLink.onclick = confirmNav;
 function confirmNav() {
  return confirm(theMessage);
 document.body.onload = updateLinks;
Categories: SharePoint 2007
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: