I am using SharePoint Foundation 2010 and attempting to have my PDFs open in a new tab or window. I have been able to get this to work from document libraries by using jQuery. You can see this code below. One of the reason I am using this is to avoid the user being prompted for credentials every time they open the a PDF.

$("a[target!='_blank'][href$='.pdf']").attr("target", "_blank").removeAttr("onclick");

I also have Search Server Express 2010 setup on this server. When I try to run this same jQuery code on the results.aspx page it responds different. It is forcing a download of the PDF (the natural action) as well as opening it in a new tab/window (as I have added). I tried to add similar code to this below to prevent the downloading of the PDF. I just want it to open in a new window/tab.

 $("a[target!='_blank'][href$='.pdf']").attr("target", "_blank").removeAttr("onclick").click(function (e) {

If anybody has any suggestions or pointers, that would be great.

1 Answer 1


I found this solution and it works well for me. I do not have the Search Server Express as part of my SP Foundation 2010 installation, so I can't answer whether this will have any affect with it. This is also a jQuery solution, albeit a little longer.

This code should be places before the closing tag.

<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
            function ()
                    // has to be on an interval for grouped doc libraries
                    // where the actual links are loaded only once a group
                    // is expanded
                    function ()
                        $("a[onclick*='return DispEx'][target!='_blank']")
                        .attr("target", "_blank")

                        // document type icons
                        .click(function (e)
                                window.open($(this).attr("documentUrl"), "_blank");
                                return false;
                        .each(function ()
                                    .replace(/["'{}]/g, "")
                                this.onclick = null;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.