日期:2014-05-16 浏览次数:20548 次
????? 项目中使用到pdf在线预览功能,本来使用flexpaper在线预览的,效果虽然好但是要把pdf转换成swf格式才行,后来直接用Adobe Reader 显示了,但要是客户机没有安装Adobe Reader就会出现问题,pdf文件就直接变成了下载,所有要先判断下客户机有没有安装,没安装就提示安装
????? 使用javascript代码检测是否安装Adobe Reader ActiveX。另外,若未安装直接跳转到adobe reader下载的页面,提示用户下载并安装。
function Check_AdobeReader() { var displayString; var acrobat = new Object(); acrobat.installed = false; acrobat.version = "0.0"; if (navigator.plugins && navigator.plugins.length) { for (x = 0; x < navigator.plugins.length; x++) { if (navigator.plugins[x].description.indexOf("Adobe Acrobat") != -1) { acrobat.version = parseFloat(navigator.plugins[x].description.split("Version ")[1]); if (acrobat.version.toString().length == 1) acrobat.version += ".0"; acrobat.installed = true; displayString = "Acrobat Version: " + acrobat.version; break; } else if (navigator.plugins[x].description.indexOf("Adobe PDF Plug-In") != -1) { acrobat.installed = true; acrobat.version = "8+"; displayString = "Acrobat Version 8 or Above"; } } } else if (window.ActiveXObject) { for (x = 2; x < 10; x++) { try { oAcro = eval("new ActiveXObject('PDF.PdfCtrl." + x + "');"); if (oAcro) { acrobat.installed = true; acrobat.version = x + ".0"; displayString = "Acrobat Version: " + acrobat.version; } } catch (e) { } } try { oAcro4 = new ActiveXObject("PDF.PdfCtrl.1"); if (oAcro4) { acrobat.installed = true; acrobat.version = '4.0'; displayString = 'Acrobat Version: ' + acrobat.version; } } catch (e) { } try { oAcro7 = new ActiveXObject('AcroPDF.PDF.1'); if (oAcro7) { acrobat.installed = true; acrobat.version = '7.0'; displayString = 'Acrobat Version: ' + acrobat.version; } } catch (e) { } } return acrobat; }
?
function isAcrobatPluginInstall() { var flag = false; // 如果是firefox浏览器 if (navigator.plugins && navigator.plugins.length) { for (x = 0; x < navigator.plugins.length; x++) { if (navigator.plugins[x].name == 'Adobe Acrobat') flag = true; } } // 下面代码都是处理IE浏览器的情况 else if (window.ActiveXObject) { for (x = 2; x < 10; x++) { try { oAcro = eval("new ActiveXObject('PDF.PdfCtrl." + x + "');"); if (oAcro) { flag = true; } } catch (e) { flag = false; } } try { oAcro4 = new ActiveXObject('PDF.PdfCtrl.1'); if (oAcro4) flag = true; } catch (e) { flag = false; } try { oAcro7 = new ActiveXObject('AcroPDF.PDF.1'); if (oAcro7) flag = true; } catch (e) { flag = false; } } if (flag) { return true; } else { alert("对不起,您还没有安装PDF阅读器软件呢,为了方便预览PDF文档,请选择安装!"); location = 'http://ardownload.adobe.com/pub/adobe/reader/win/9.x/9.3/chs/AdbeRdr930_zh_CN.exe'; } return flag; }
?