I am trying to detect the Adobe Reader plugin for IE11, but for some reason it always returns 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.
I got my code directly from this site (a user from this website!): .html
The code works brilliantly until IE11 on Windows 7, where it returns null in getAcrobatVersion.
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="/" 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.');
}
I am trying to detect the Adobe Reader plugin for IE11, but for some reason it always returns 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.
I got my code directly from this site (a user from this website!): http://thecodeabode.blogspot./2011/01/detect-adobe-reader-plugin.html
The code works brilliantly until IE11 on Windows 7, where it returns null in getAcrobatVersion.
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./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.');
}
Share
Improve this question
asked Jan 31, 2014 at 16:49
MormodesMormodes
251 silver badge4 bronze badges
3
- Theoretically, IE11 should be using navigator.plugins for its addons like all other browsers. In practice, this doesn't seem to be the case all the time, so you might need to try checking both. (I encountered this with Flash - my development puter used ActiveXObject, then another person's puter had it in the browser-standard plugins list) – Katana314 Commented Jan 31, 2014 at 16:58
- @Katana314: that sounds like it might be patibility mode causing that? – Spudley Commented Jan 31, 2014 at 17:04
- @Spudley For example: Here, on Stack Overflow, my navigator.plugins object is an empty array. However, on the separate puter in a nearby office (possibly where Flash was installed more recently) it's an array with a number of plugin objects, like Flash. In Developer Tools, the emulation mode shows Edge (normal) for both. Here's Microsoft's page with a good code example on how best to detect Silverlight (can be adapted to the plugin you want): msdn.microsoft./en-us/library/ie/dn423948(v=vs.85).aspx – Katana314 Commented Jan 31, 2014 at 17:08
3 Answers
Reset to default 3if(userAgent.indexOf("msie") > -1)
will no longer do the job in IE11 because the user agent string has changed. For IE11, you have to look for Trident
.
MediaElement.js worked around this like so:
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. If you see that object just use the same method that works for Chrome or Firefox.
http://msdn.microsoft./en-us/library/ie/dn423948(v=vs.85).aspx
userAgent.indexOf("msie")
will not work in IE11. hey changed the user agent string. All the rest follows from that, as all your getBrowserName() == ie
tests will fail.
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)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745093266a4610820.html
评论列表(0条)