IE 9 Flash使用JavaScript检测 [英] IE 9 flash detect with javascript
问题描述
检查是否存在Flash插件,仅在IE中失败(即使使用开发人员工具更改了浏览器和文档模式,也可以认为它基本上是IE 9的JavaScript引擎).
Checking if flash plugin present, failing only in IE (think its basically the javascript engine of IE 9, even when browser&document mode changed with developer tools).
var is_Flash = false;
var is_FlashVersion = 0;
var plugin = (navigator.mimeTypes &&
navigator.mimeTypes["application/x-shockwave-flash"] &&
navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) ?
navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if (plugin&&plugin.description) {
is_Flash = true;
is_FlashVersion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1));
}
IE不会返回插件详细信息. 有人知道解决方案吗?
IE doesnt return the plugin details. Anyone know of a solution?
可以使用它来检查对象的详细信息,即在mimeTypes对象上IE完全没有任何内容,长度为0.
Can use this to check the object details, IE simply nothing and 0 length on the mimeTypes object.
var obj = navigator.mimeTypes["application/x-shockwave-flash"];
var out = '';
for (var i in obj) {
out += i + ": " + obj[i] + "\n";
}
alert(out);
推荐答案
您需要查看ie中的ActiveXObjects.
You need to look at ActiveXObjects in ie.
前一段时间我写了这个小函数,也许您可以从中得到一些启发,但是我没有在ie9中对其进行过测试.-
I wrote this little function a while back, maybe you can get some inspiration from it, i have not tested it in ie9 however.-
function hasFlashVersionOrBetter(major, minor) {
minor = minor || 0;
var v;
if (navigator.plugins && navigator.plugins.length > 0) {
var type = 'application/x-shockwave-flash';
var mimeTypes = navigator.mimeTypes;
if (mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description) {
v = mimeTypes[type].enabledPlugin.description.replace(/^.*?([0-9]+)\.([0-9])+.*$/, '$1,$2').split(',');
}
}
else {
var flashObj = null;
try { flashObj = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); } catch (ex) { return false; }
if (flashObj != null) {
var fV;
try { fV = flashObj.GetVariable("$version"); } catch (err) { return false; }
v = fV.replace(/^.*?([0-9]+,[0-9]+).*$/, '$1').split(',');
}
}
if (v) {
var majorVersion = parseInt(v[0], 10);
return major > majorVersion || major == majorVersion && minor >= parseInt(v[1], 10);
}
return false;
}
这篇关于IE 9 Flash使用JavaScript检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!