3

单击 IFrame 中的链接时,我使用 IFrame 查看 Pdf 文档。但是,在没有阅读器的机器上,链接会提示下载。有没有办法,当它检测到没有阅读器时,相同的链接可以提示用户下载阅读器?我以为我在某个地方看到过这个。谢谢!

4

4 回答 4

5

这在 IE 中对我有用:

<script>
var p;
try {
p = new ActiveXObject('AcroExch.Document');
}
catch (e) {
// active x object could not be created
document.write('doesnt look like the PDF plugin is installed...');
}
if (p) {
    document.write('does look like the pdf plugin is installed!');
}
</script>

在这里找到它。..但修改为删除“endif”

于 2009-08-12T16:10:05.023 回答
4

我知道这个问题已经得到解答,但我最近不得不构建一个功能来检测跨不同浏览器的 PDF 插件存在。这就是我得到的。希望有帮助。

function hasPdfPlugin() {   
//detect in mimeTypes array
if (navigator.mimeTypes != null && navigator.mimeTypes.length > 0) {        
    for (i = 0; i < navigator.mimeTypes.length; i++) {
        var mtype = navigator.mimeTypes[i];
        if(mtype.type == "application/pdf" && mtype.enabledPlugin)
            return true;
    }
}

//detect in plugins array
if (navigator.plugins != null && navigator.plugins.length > 0) {
    for (i = 0; i < navigator.plugins.length; i++) {
        var plugin = navigator.plugins[i];
        if (plugin.name.indexOf("Adobe Acrobat") > -1
                || plugin.name.indexOf("Adobe Reader") > -1) {
            return true;
        }

    }
} 
// detect IE plugin
if (window.ActiveXObject) {
    // check for presence of newer object       
    try {
        var oAcro7 = new ActiveXObject('AcroPDF.PDF.1');
        if (oAcro7) {
            return true;
        }
    } catch (e) {
    }

    // iterate through version and attempt to create object 
    for (x = 1; x < 10; x++) {
        try {
            var oAcro = eval("new ActiveXObject('PDF.PdfCtrl." + x + "');");
            if (oAcro) {
                return true;
            }
        } catch (e) {
        }
    }

    // check if you can create a generic acrobat document
    try {
        var p = new ActiveXObject('AcroExch.Document');
        if (p) {
            return true;
        }
    } catch (e) {
    }

}

// Can't detect in all other cases
return false;
}
于 2010-10-25T20:35:12.730 回答
3

以下是一些有助于检测 Acrobat 存在的脚本。

于 2009-08-12T07:08:14.027 回答
1

在 JavaScript 中,您可以执行以下操作:

var adobePdfObject = new ActiveXObject("theAdobePdfCOMObject");

然后要么捕获失败错误,要么捕获 adobePdfObject 的返回值?

于 2009-08-12T06:53:30.000 回答