none
how to open PDF document in new tab in same browser in sharepoint 2010?

    Pertanyaan

  • Hi All; 

    I am having pdf files in my document library. I want that document to be open in browser in new window. In Opera and Firefox it is working fine but in IE and Chrome is it not opening it is directly downloads the pdf file. I want to open it in new tab of same browser please help me.  

    13 Maret 2012 6:37

Jawaban

  • Hi,

    currently no browser supports open in tabs by using a special markup style. The default behaviour of Opera and Firefox is that the browser itself open this kind of document in a new browser tab. When use target="_blank" on a hyperlink then a new browser window will be opened. But there is no target="_tab" that can be specified.

    You can only control the new window opening with a javascript. but i bet this isn't what you are looking for.

    Kind regards
    Stefan


    http://www.n8d.at/blog
    Follow me on Twitter: StFBauer | n8design

    Microsoft Community Contributor 2011
    MCTS - SharePoint / WSS Configuration and Development

    13 Maret 2012 6:50

Semua Balasan

  • Hi Amol,

    You have to set the browser settings.

    For IE

    Select Tools -> Internet Options - > Select Tab Security - > Select Internet Zone and click custom level. Scroll down and select Download and set according to your choice.


    My Blog
    Twitter @jaggavivek

    13 Maret 2012 6:45
  • Hi,

    currently no browser supports open in tabs by using a special markup style. The default behaviour of Opera and Firefox is that the browser itself open this kind of document in a new browser tab. When use target="_blank" on a hyperlink then a new browser window will be opened. But there is no target="_tab" that can be specified.

    You can only control the new window opening with a javascript. but i bet this isn't what you are looking for.

    Kind regards
    Stefan


    http://www.n8d.at/blog
    Follow me on Twitter: StFBauer | n8design

    Microsoft Community Contributor 2011
    MCTS - SharePoint / WSS Configuration and Development

    13 Maret 2012 6:50
  • Hi Stefan, 

    Thanks for replying. I use target="_blank" it wont work. If there is any java script then i am ready to use it. Please provide me information about javascript. and how to use it.

    13 Maret 2012 7:05
  • Hi Amol,

    You have to modify the XSLT of your dataview as

    <a href="URL" target="_blank">Filename/name</a>

    or

    <a>
    <xsl:attribute name="href">
    <xsl:value-of select="URL" />
    <xsl:attribute name="target">
    <xsl:value-of select="_blank" />

    </xsl:attribute>

    <xsl:value-of select="Filename/name"/>
    </a>


    My Blog
    Twitter @jaggavivek

    13 Maret 2012 7:21
  • I am having a simple web part page. I have taken a content editor web part and add one line <a href="location of my pdf" _target="_blank> click here </a> 

    how to add xsl stylesheet to it?

    13 Maret 2012 9:22
  • Hello!

    Please, try to run this script.


    Bond... Brooke Bond!

    13 Maret 2012 9:51
  • Thanks All for relying, 

    but still it don't work. I am trying it out on my demo site on "OFFICE 365" So please suggest other options for Sharepoint online. 

    13 Maret 2012 12:33
  • Hi Amol,

    As per my assumption, you have a pdf file in a SharePoint document library and on a page you have to show the link of pdf file in a Content Editor webpart.

    For the same you have to write the following html in content editor webpart as

    < a href="pdf file path" target="_blank">File name/ custom text</a>


    My Blog
    Twitter @jaggavivek


    13 Maret 2012 12:42
  • Thanks vivek,

    I try this also see i have this code in my content editor 

    <div class="single">
    <h2> <b> <a href="Documents/Brochure.pdf" >  Brochure </a> </b> </h2> 
    <p> An overview of features, capabilities and how it can facilitate  projects </p> <br/> 
    </div> 

    it is not working with _blank and _tab attribute. Is there any java script solution available?

    13 Maret 2012 13:04
  • Amol,

    Try this

    <div class="single">
    <h2> <b> <a href="Documents/Brochure.pdf" target="_blank" >  Brochure </a> </b> </h2> 
    <p> An overview of features, capabilities and how it can facilitate  projects </p> <br/> 
    </div> 


    My Blog
    Twitter @jaggavivek



    14 Maret 2012 10:05
  • hi Vivek, 

    As i mention _blank and _tab bot attributes are not working. I use both of this attributes but it is not working.

    If there is any java script code please give me that. 

    14 Maret 2012 12:43
  • Amol,

    Can you please share the screen shot of your written code and error if any...


    My Blog
    Twitter @jaggavivek

    14 Maret 2012 12:55
  • hi vivek, 

    I am using simple content editor in which i have this code 

     <div class="single-post">
     <h2> <b> <a href="/Documents/Zen%20Brochure.pdf" target="_blank"> Brochure </a> </b> </h2> 
     <p> An overview of  features, capabilities and how it can facilitate agile implementation of projects </p> <br/> 
    </div>  I am having this code only. 
    16 Maret 2012 4:33
  • I am using following java script which is useful but it is not working in google chrome browser can you suggest me anything. I am giving code for script which i am using. 

    <script type="text/javascript">
      function IncludeJS(jsFile)
    {//includes external js file when this one loads
    //usage
    //IncludeJS('jsFile.js');
      document.write('<script type="text/javascript" src="'
        + jsFile + '"></scr' + 'ipt>'); 
    }
    //required jquery library
    IncludeJS('https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js');
        //The script will run after the page is loaded
        ExecuteOrDelayUntilScriptLoaded(Page_Load,"SP.js");
        // Load the page. 
        function Page_Load() {
            try
                {
    var siteCollectionUrl = document.location.protocol + "//" + 
     document.location.host + _spPageContextInfo.siteServerRelativeUrl;  //sitecollection url not needed for relative image location
    var pdfImgLoc =  "/utilities/ICPDF.gif";  
                    //setting icons
                    var $pdficons = $("td[class='ms-vb-icon'] img[title*='.pdf' class!='ms-vb-icon-overlay']");//added * to catch checked out docs - excluded overlay imgs
        $pdficons = $pdficons.add("img[src='/_layouts/images/pdficon.gif']");
                    $pdficons.each(function(index)
                                    {
                                        //var pdfImgLoc = siteCollectionUrl + "/utilities/ICPDF.gif"; //moved to top of function for one-time variable set
                                        $(this).attr({src: pdfImgLoc});
                                    }
                                   );
                    //assign javascript for the pdf files
                    //var $items = $('.ms-vb a[href$=".pdf"]');
        var $items = $('a[href$=".pdf"]');  //removed .ms-vb class selector to catch public site links and app page links
                    $items.each(function(index) 
                                    {                                   
    var $itemURL =  document.location.protocol + "//" + 
    document.location.host + $(this).attr('href');
    //var $itemURL =  $(this).attr('href');
             $(this).removeAttr("onclick");
                                        $(this).unbind("click");


                                        $(this).attr({
                                                onclick: 'javascript:OpenPDF("' + $itemURL + '"); return false',
                                                onmousedown: "return VerifyHref(this,event,'0','','')"


                                            });   //return false added so href is not followed when open new window - quote marks swapped to handle file names with apostrophe                       
                                     }
                                );
                }
                catch (e) {
                    alert(e.message);
                    }
            }
       function OpenPDF(itemPath) {
       myTitle = itemPath.split('/').pop().toString()
       myWindow = window.open("", "",'toolbar=no') 
       myWindow.document.write('<embed id="PDF" width="100%" height="100%" src="' + itemPath +'" type="application/pdf" />');//quote marks swapped to handle file names with apostrophe 
       myWindow.document.title = myTitle
       myWindow.document.close() 
            }
    //end required code
    //Optional Grouped View Fix 
    // Override ExpGroupRenderData in init.js to call Page_Load() upon expand group
    ExpGroupRenderData = (function (old) {
        return function (htmlToRender, groupName, isLoaded) {
        var result = old(htmlToRender, groupName, isLoaded);
    Page_Load();
    };
    })(ExpGroupRenderData);


    ExpCollGroup = (function (old) {
        return function (c,h,m,l) {
        var result = old(c,h,m,l);
    Page_Load();
    };
    })(ExpCollGroup);
    //End Override
    //optional Open PDF in Browser Menu Item
    //Add Doc Item Menu 'Open PDF in Browser'
    function Custom_AddDocLibMenuItems(m, ctx)
    {
    var strDisplayText="Open PDF in Browser";
    var d= m.parentElement
    var a;
    while(a!=null&&a.tagName!="CTXName")a=FindSTSMenuTable(d,"CTXName");
    var b = itemTable.getElementsByTagName('a')[0];
    var c = b.href;
    var strAction='OpenPDF("' + c + '"); return false'
    var strImagePath="/utilities/icpdf.gif";
    //alert(strAction);
    //check if pdf extention
    var fileExt = c.split('.').pop().toLowerCase(); 
    if (fileExt == "pdf")

    //add menu item
    CAMOpt(m, strDisplayText, strAction, strImagePath);
    }
     // add a separator to the menu
    CAMSep(m);
    //return false to render default menu options or True to prevent default menu
    return false; 
    }
    //End Add Doc Item Menu
      </script>

    16 Maret 2012 4:35
  • Amol,

    You editor code seems correct. What will happen after click "Brochure" link?


    My Blog
    Twitter @jaggavivek


    16 Maret 2012 4:42
  • After clicking on Brochure It saves file don't open in new browser. So I apply the Above Java script. It is opening in new tab of Browser but Only Problem is now Google Chrome. It is not functioning in Google Chrome. Please refer to the script above. This work. Only in Google Chrome the pdf is not opening. Can you please suggest me some change in script? so that it will work in Google Chrome.
    16 Maret 2012 5:25
  • What do you have the Browser File Handling option in the Web Application set to?

    SharePoint Central Administration --> Manage Web Applications --> Select The Web Application --> General Settings --> Browser File Handling

    You need to set it to permissive to allow PDF's to open in browser. With this set it should allow you to use:

    <a href="#" target="_blank"></a>


    Brian T. Shell

    16 Maret 2012 6:07
  • Thanks Brian, 

    This works on my Local Environment of SharePoint 2010. But my Site is on Sharepoint online. i.e. On office365 so it don't have this functionality in office 365 central admin. You have any other way to open PDF in Browser on Office 365? 

    Please reply.

    16 Maret 2012 7:00
  • This link might help you with your issue:

    http://techblurt.com/2012/03/02/office365-open-pdf-in-the-browser/


    Brian T. Shell

    16 Maret 2012 15:52