[英]Detecting Adobe Reader in ie11 with JavaScript
I am trying to detect the Adobe Reader plugin for IE11, but for some reason it always returns null. 我正在尝试检测IE11的Adobe Reader插件,但是由于某种原因,它总是返回null。 I am lead to believe it is because IE11 doesn't use the same plugin name as older versions of Internet Explorer, but I am not sure.
我被认为是因为IE11使用的插件名称与旧版本的Internet Explorer不同,但是我不确定。
I got my code directly from this site (a user from this website!): http://thecodeabode.blogspot.com/2011/01/detect-adobe-reader-plugin.html 我直接从此网站(该网站的用户!)获得了代码: http : //thecodeabode.blogspot.com/2011/01/detect-adobe-reader-plugin.html
The code works brilliantly until IE11 on Windows 7, where it returns null in getAcrobatVersion. 该代码在Windows 7上的IE11之前一直运行良好,在getAcrobatVersion中返回null。
Here is the full code so it's easier for you all: 这是完整的代码,因此对您来说更容易:
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();
if(info.acrobat){
//IE11 will return false even if you have adobe reader because it's a terrible browser.
document.write('<img src="img/sysChkErr.gif" alt="" border="0">');
document.write('<span style="color: ' + errCol + '"><strong>Not Installed</strong></span>');
document.write('<br /><br />Some of our applications require Adobe Reader. You can download Adobe Reader ');
document.write('<a href="http://get.adobe.com/reader/" target="_blank">here</a>.');
}else{
document.write('<img src="img/sysChkPas.gif" alt="" border="0">');
document.write('<span style="color: ' + pasCol + '"><strong>Installed</strong></span>');
document.write('<br /><br />Version ' + info.acrobatVersion + ' is installed.');
}
if(userAgent.indexOf("msie") > -1)
will no longer do the job in IE11 because the user agent string has changed . if(userAgent.indexOf("msie") > -1)
用户代理字符串已更改, if(userAgent.indexOf("msie") > -1)
将不再执行IE11中的工作。 For IE11, you have to look for Trident
. 对于IE11,您必须查找
Trident
。
MediaElement.js worked around this like so: MediaElement.js可以这样解决:
t.isIE = (nav.appName.match(/microsoft/gi) !== null) || (ua.match(/trident/gi) !== null);
So I guess this might do the trick for you? 所以我想这可能对您有用吗?
else if(userAgent.indexOf("msie") > -1 || userAgent.indexOf("trident") > -1) return "ie";
You don't need to do a bunch of crazy browser detects. 您无需进行一堆疯狂的浏览器检测。 IE11 has made this easier because they support
navigator.plugins
now. IE11使其变得更容易,因为它们现在支持
navigator.plugins
。 If you see that object just use the same method that works for Chrome or Firefox. 如果看到该对象,请使用适用于Chrome或Firefox的相同方法。
http://msdn.microsoft.com/en-us/library/ie/dn423948(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/ie/dn423948(v=vs.85).aspx
userAgent.indexOf("msie")
will not work in IE11. userAgent.indexOf("msie")
在IE11中不起作用。 hey changed the user agent string. 嘿,更改了用户代理字符串。 All the rest follows from that, as all your
getBrowserName() == ie
tests will fail. 其余所有操作都将随之而来,因为所有的
getBrowserName() == ie
测试将失败。
Either change you detection code to work for all IE versions (look for trident
instead of/as well as msie
), or else use a different method to determine what to do (detecting the existence of the activeX
object might be a good alternative) 要么改变你检测代码为所有IE版本的工作(寻找
trident
,而不是/以及msie
),或者使用不同的方法来确定做什么(检测存在activeX
对象可能是一个很好的选择)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.