A request that I get occasionally is how to force SharePoint to open up PDF files up in a new window. Assuming you have Adobe Reader installed, the default behavior is to prompt the user to open the PDF file. For some customers, they want it to automatically open up in the same browser window. This is easy to do by following the answer shown here. (Note: this does assume that the browser plug-in is installed and enabled).
For me, I like this solution and simply use the back button when I’m done and want to return to SharePoint. If I want it in a new window, I either hold down Ctrl and click the link or just right-click the link and select Open in New Window. Basic browser stuff, right? In most cases, I convince the customer that this is a training issue on how to use the browser. However, that doesn’t always fly with every customer, does it?
If you to force the PDF file to load into a new browser window, keep reading...
I think I have a pretty-good workaround that addresses the problem. This is a page-specific fix, so it is not global to all libraries or links in your farm. I like it this way as you have granular control where you want to use it, meaning you may only want to use it on certain pages within team sites.
The solution is to add this code to a Content Editor Web Part (CEWP) on the page:
// Get the collection of <a> tags
var aAllLinks = document.getElementsByTagName('a');
// For each <a> tag
var oA = aAllLinks[i];
var sHREF = oA.attributes["href"].value.toLowerCase();
// Is this a pdf link?
if(sHREF.indexOf(".pdf") > 0)
Credit goes to Daniel whose code I modified to have this functionality. To simplify this for all of you, I am also making this available using a .DWP web part. You can simply upload this into the web part gallery of your site collection which allows you to more easily add it to any page. To download, click here.