当点击该IFrame中的链接时,我使用IFrame查看Pdf文档。但是,在没有阅读器的计算机上,链接将提示下载。有没有办法,相同的链接可以提示用户在检测到没有读卡器时下载阅读器?我以为我在某个地方见过这个。谢谢!
答案 0 :(得分: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>
Found it here. ..但已修改为删除“endif”
答案 1 :(得分:3)
Here are a few scripts有助于检测Acrobat的存在。
答案 2 :(得分:3)
我知道这个问题已经得到了解答,但我最近不得不构建一个能够检测不同浏览器中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;
}
答案 3 :(得分:1)
在JavaScript中,您可以执行以下操作:
var adobePdfObject = new ActiveXObject("theAdobePdfCOMObject");
然后捕获失败错误或adobePdfObject的返回值?