Sunday, September 28, 2014

How to open PDF document files in a new browser tab in SharePoint

Open PDF Files in a New Browser Tab
By default SharePoint PDF files opens in current window and end user feeling that he came out of SharePoint navigation. So clients are asking they want to open PDF files in a new tab instead of the current window. 

Over the net there are so many users telling that use content editor web part with javascript to open the PDF file in new window but it would be very difficult to add each document library and each page. So i tried in another way that is if i can add the javascript on master page then it will be applied to each and every page on SharePoint so that i can solve the problem then i tried and applied.
Everything is working perfect and clients are happy :).

Step 1: Download the latest version of jQuery (I used version 1.7.2 for this example)
Step 2: Upload the jQuery file to a document library within the site collection
Step 3: Make sure all users have read access to the document library
Step 4: Add the following code with your Master Page’s body tag
<script src="/Style library/javascript/jquery-1.7.2.min.js"type="text/javascript">
</script>
<script>
$(document).ready(function(){
  $("a[href$='.pdf']").removeAttr('onclick').attr("target","_blank");
});


</script>
Save and publish your master page.

No comments:

Post a Comment