Stump the Panel » jQuery for Everyone

jQuery libraries and functions available to all pages (open PDFs in new window)

(2 posts)
  1. Hi,
    Did the 'superstar' webinar a of weeks back and it was really useful - thanks to Paul & Mark.

    Since then I have had the requirement to, site-collection-wide, force all PDF files to open in a new window. (Users were always clicking the top right [X] closing their browser after reading the PDF).

    After a bit of hacking about (I'm no programmer) I came up with the following code:

    <script type="text/javascript">
    //?PageView=Shared&ToolPaneView=2
    if(typeof jQuery=="undefined"){
    	var jQPath="/sites/dendron/javascripts/";
    	document.write("<script src='",jQPath,"jquery.min.js' type='text/javascript'><\/script>");
    }
    </script>
    
    <script type="text/javascript">
    
    //Open pdf files in new window
    
    $("a[href*=.pdf]").click(function(){
    	window.open(this.href);
    	return false;
    });
    
    </script>

    This works fine (as long as I put the CEWP after the List WP) - but has to be hand coded onto each and every page ... :-(

    I *think* Paul G mentioned that Toni had maybe come up with a work around.

    My guess is that I can add a call to the jQuery library in the master.page and then add the function call to ?the footer? of the master.page.

    Is this bad practice? Would you suggest another route in to applying this?

    Many thanks,
    Ben

    Posted 1 month ago #
  2. Hi Ben,

    Yes, you are correct you just need to past the script you need to your master page and all pages will have it. :)))

    I pasted it just before </body> tag.

    Let me know,
    --
    Toni
    http://www.sharepointusecases.com

    Posted 1 month ago #

RSS feed for this topic

Reply

You must log in to post.