//检测浏览器类型:IE、火狐、谷歌、Safari
function getBrowserName(){
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 || userAgent.indexOf("trident") > -1) return "ie";
else if(userAgent.indexOf("firefox") > -1) return "firefox";
return userAgent;
}
//针对IE返回ActiveXObject
function getActiveXObject (name){
try {
return new ActiveXObject(name);
} catch(e) {
}
}
//针对除了IE之外浏览器
function getNavigatorPlugin (name){
for(key in navigator.plugins) {
var plugin = navigator.plugins[key];
if(plugin.name == name)
return plugin;
}
}
//获取Adobe Reader插件信息
function getPDFPlugin(){
if(getBrowserName() == 'ie') {
return getActiveXObject('AcroPDF.PDF') || getActiveXObject('PDF.PdfCtrl');
}
else {
return getNavigatorPlugin('Adobe Acrobat') || getNavigatorPlugin('Chrome PDF Viewer') || getNavigatorPlugin('WebKit built-in PDF');
}
}
//判断插件是否安装
function isAcrobatInstalled(){
return !!getPDFPlugin();
}
function getAcrobatVersion(){
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;
}
}
//插件没安装
if(!isAcrobatInstalled()){
//检测到未安装阅读器,则提示用户下载
var mymessage=confirm("你可能还没有安装pdf阅读器,为了方便你查看pdf文档,请下载安装!");
if(mymessage==true){
var url = "resource!downloadMaterial.do?fileName=readerdc_cn_ha_crd_install.exe";
url = encodeURI(encodeURI(url));
location.href=url;
}
}
js检测PDF插件 Adobe Reader是否安装
最新推荐文章于 2022-07-16 20:26:31 发布