【问题标题】:How to disable Google Chrome's "Chrome PDF Viewer" using Asp.net如何使用 Asp.net 禁用 Google Chrome 的“Chrome PDF 查看器”
【发布时间】:2012-03-19 10:19:27
【问题描述】:

由于一些不可避免的原因我需要禁用谷歌浏览器的“Chrome PDF 查看器”并启用adob PDF 查看器。我想从 C#.net 和 asp.net 代码中执行此操作。 我知道这是不可能的,因为它与客户端计算机上的更改设置有关,但如果她/他,我准备征求用户的许可想要禁用默认查看器。

这项工作背后的原因是,由于 Chrome 的默认阅读器,我在 iTextSharp 创建的所有 PDF 在 Google Chrome 中都无法正常运行。并非所有用户都可以手动查找和禁用插件,因此我希望它通过代码完成。我需要知道我们如何禁用默认的 PDF 查看器。之后,我的问题将自动解决。请给我有关代码的任何建议

【问题讨论】:

    标签: asp.net c#-4.0 google-chrome google-chrome-extension


    【解决方案1】:

    谷歌浏览器插件不会改变编程方式,所以只需像弹出消息一样通知客户端

    <script type="text/javascript">
    function CheckPlugin()
    {
    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    function findPlugin(ext) {
    var thisExt, findExt;
    for (var n = 0; n < navigator.plugins.length; n++) {
    //alert("n value"+ navigator.plugins.length);
    for (var m = 0; m < navigator.plugins[n].length; m++) {
    //alert("m length:"+navigator.plugins[n].length);
    thisExt = navigator.plugins[n][m].description.toLowerCase();
    // alert("this exten"+thisExt);
    findExt = thisExt.substring(0, thisExt.indexOf(" "));
    //alert("findexes"+findExt);
    if (findExt == ext)
    return (true);
    }
    }
    return (false);
    }
    
    if (is_chrome ==true) {
    //alert("chrome browser");
    if (findPlugin("acrobat")) {
    //alert("Adobe Acrobat pdf viewer");
    return true;
    }
    else {
    
    alert("please disable the chrome pdf viewer and enable the Adobe Acrobat PDF viewer \n Please follow the steps:\n 1.Open the new tab 'chrome://plugins/' type the Address. \n 2. Click the Enable link in 'Adobe Acrobat' field. \n 3. click the Disable link in 'Chrome PDF Viewer'. \n 4. Close the tab and you can open the PDf files in chrome browser.");
    return false;
    }
    }
    else {
    //alert("not chrome");
    }
    }
    
    </script>
    

    在超链接中这样写

    <asp:HyperLink ID="HyperLink1" runat="server"
    NavigateUrl="~/PDFFiles/AGENCY PROFILE APP.pdf" onclick="return CheckPlugin();">Agency profile app</asp:HyperLink>
    

    我觉得是比较有帮助的。

    【讨论】:

      【解决方案2】:

      只要您将 pdf 嵌入到 html 文件中,以下内容可能对您有用....
      尝试将嵌入的type 更改为type="application/vnd.adobe.pdfxml",我知道这不是您的服务,但是当我在普通 pdf 上尝试它时,插件没有阻塞并使用 Adob​​es 插件显示 pdf,而无需禁用默认 (Chromes)阅读器。
      我不得不在一个有点旧的 Adob​​e 插件版本上进行测试,因为我在拨号时,并且不会为了测试而下载一个 50 兆的文件;)。所以你应该在最新的插件上测试它。
      希望它对你有帮助。

      编辑:
      下面是如何使 pdf 占据全屏的示例页面,就像您直接指向文件一样...
      http://pdfobject.com/markup/examples/full-browser-window.html
      ...这也是我进行测试的页面。

      【讨论】:

        【解决方案3】:

        我使用 iTextSharp,当同时启用 Chrome PDF 和 Adob​​e 时,Chrome 会导致问题。即使表单指定将数据作为 XFDF 发送,提交按钮也会将 FDF 数据发送回服务器。将 ContentType 设置为“application/vnd.adobe.pdfxml”即可解决问题。

        向 PAEz 致敬。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-02-18
          • 2011-10-30
          • 2017-01-23
          • 2022-09-27
          • 2013-03-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多