Home  >  Article  >  Web Front-end  >  JavaScript study notes (17) Detecting browser plug-in code_Basic knowledge

JavaScript study notes (17) Detecting browser plug-in code_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:52:28963browse
Copy code The code is as follows:

//Detect non-IE browser plug-in function
function hasPlugin( name) {
name = name.toLowerCase();
for (var i=0 ; i < navigator.plugins.length ; i ) {
if (navigator.plugins[i].name. toLowerCase().indexOf(name) >-1) {
return true;
}
}
return false;
}

//Detect IE browser Plug-in function
function hasIEPlugin(name) {
try {
new ActiveXObject(name);
return true;
}
catch (ex) {
return false;
}
}
//Detect Flash in all browsers
function hasFlash() {
var result = hasPlugin("Flash");
if (!result) {
result = hasIEPlugin("ShockwaveFlash.ShockwaveFlash");
}
return result;
}
//Detect QuickTime in all browsers
function hasQuickTime() {
var result = hasPlugin("QuickTime");
if (!result) {
result = hasIEPlugin("QuickTime.QuickTime");
}
return result;
}

alert(hasFlash());
alert(hasQuickTime());
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn