【问题标题】:How to show message if Adobe Reader is not installed?如果未安装 Adob​​e Reader,如何显示消息?
【发布时间】:2014-03-02 05:38:43
【问题描述】:

我已经在我的页面上嵌入了 PDF,使用“<iFrame>”我正在调用一个包含 <Object> 标记的 HTML 页面,其中有一个嵌入 PDF 的 <embed> 标记和一个

标签在没有安装 Adob​​e Reader 时显示。

在 Firefox、Chrome 和 IE 11 上,如果安装了 PDF 阅读器,它将仅显示 PDF,但当没有安装阅读器时,它会在 <p> 标签中显示消息“安装Adobe 阅读器”。

我的问题是:- 在 IE10 中,即使安装了 Adob​​e 阅读器,它也会在 <p> 标签中显示消息“安装 Adob​​e 阅读器”。 如果安装了 Adob​​e Reader,请建议如何隐藏该消息,并且该消息应仅在未安装 PDF Reader 时显示。

这是我的代码:

Iframe 代码从中调用 PDF 页面:

            <div id="pdf">

            <iframe id="pdfIframe" name="pdfIframe" src="pdfView.html" style="width: 100%; height: 100%;" scrolling="auto" frameborder="1">
                Your browser doesn't support inline frames.
            </iframe>
        </div>

PDF页面代码:

<body>
<style>
    html, body, #blankPane {
        height: 100%;
        margin: 0;
        padding: 0;
    }

        #blankPane p {
            font-weight: bold;
            line-height: 30px;
            height: auto;
            width: 98%;
            margin: 0 auto;
            color: #bc0000;
        }

        #blankPane * {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
</style>

<div id="blankPane" class="overflowHidden">

    <object data="lorem.pdf" type="application/pdf">
        <p>
            It appears you don't have Adobe Reader or PDF support in this web browser.
            <br />
            <a href="lorem.pdf">Click here to download the PDF</a> OR <a href="http://get.adobe.com/reader/" target="_blank">Click here to install Adobe Reader</a>
        </p>
        <embed id="pdfDocument" src="lorem.pdf" type="application/pdf" />
    </object>
</div>

请推荐!!!

【问题讨论】:

  • 这是您的浏览器,在 IE10 中您必须转到 Internet Explorer > 工具(或 Alt + t)> 管理加载项(显示:所有加载项)验证Shockwave Flash 对象已启用,否则它会告诉您它尚未安装,并且您无法使用纯客户端代码来避免这种情况。
  • 在 MVC 的帮助下我能管理什么?

标签: javascript jquery html pdf internet-explorer-10


【解决方案1】:

您可以使用如下所示的 javascript 检测安装了哪个版本的 Adob​​e Acrobat,如果您不想依赖 Adob​​e Acrobat,可以使用 FlexPaper 显示您的文档

var getAcrobatInfo = function() {

  var getBrowserName = function() {
    return this.name = this.name || function() {
      var userAgent = navigator ? navigator.userAgent.toLowerCase() : "other";

      if(userAgent.indexOf("chrome") > -1)        return "chrome";
      else if(userAgent.indexOf("safari") > -1)   return "safari";
      else if(userAgent.indexOf("msie") > -1)     return "ie";
      else if(userAgent.indexOf("firefox") > -1)  return "firefox";
      return userAgent;
    }();
  };

  var getActiveXObject = function(name) {
    try { return new ActiveXObject(name); } catch(e) {}
  };

  var getNavigatorPlugin = function(name) {
    for(key in navigator.plugins) {
      var plugin = navigator.plugins[key];
      if(plugin.name == name) return plugin;
    }
  };

  var getPDFPlugin = function() {
    return this.plugin = this.plugin || function() {
      if(getBrowserName() == 'ie') {
        //
        // load the activeX control
        // AcroPDF.PDF is used by version 7 and later
        // PDF.PdfCtrl is used by version 6 and earlier
        return getActiveXObject('AcroPDF.PDF') || getActiveXObject('PDF.PdfCtrl');
      }
      else {
        return getNavigatorPlugin('Adobe Acrobat') || getNavigatorPlugin('Chrome PDF Viewer') || getNavigatorPlugin('WebKit built-in PDF');
      }
    }();
  };

  var isAcrobatInstalled = function() {
    return !!getPDFPlugin();
  };

  var getAcrobatVersion = function() {
    try {
      var plugin = getPDFPlugin();

      if(getBrowserName() == 'ie') {
        var versions = plugin.GetVersions().split(',');
        var latest   = versions[0].split('=');
        return parseFloat(latest[1]);
      }

      if(plugin.version) return parseInt(plugin.version);
      return plugin.name

    }
    catch(e) {
      return null;
    }
  }

  //
  // The returned object
  // 
  return {
    browser:        getBrowserName(),
    acrobat:        isAcrobatInstalled() ? 'installed' : false,
    acrobatVersion: getAcrobatVersion()
  };
};

如何调用这些函数的示例:

var info = getAcrobatInfo();
alert(info.browser+ " " + info.acrobat + " " + info.acrobatVersion);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    相关资源
    最近更新 更多