This article describes the method of obtaining the flash version number of JavaScript. Share it for your reference. The specific analysis is as follows:
Next, we will introduce two js functions to determine whether the user has installed flash. If flash is installed, then get the flash version number and give a prompt.
Example 1
Get the version number of each browser, if you need to get the specific version number
Copy the code as follows: function flashChecker() {
var hasFlash = 0; //Is flash installed
var flashVersion = 0; //flash version
var isIE =/*@cc_on!@*/0; //Is it IE browser
if (isIE) {
var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
if (swf) {
hasFlash = 1;
flashVersion = swf.GetVariable("$version");
}
} else {
if (navigator.plugins && navigator.plugins.length > 0) {
var swf = navigator.plugins["Shockwave Flash"];
if (swf) {
hasFlash = 1;
flashVersion = swf.description.split(" ");
}
}
}
return {
f: hasFlash,
v: flashVersion
};
}
var fls = flashChecker();
if (fls.f) document.write("You have flash installed, the current flash version is: " + fls.v + ".x");
else document.write("You do not have flash installed");
Example 2
Copy the code as follows: function getFlashVersion() {
var flashVer = NaN;
var ua = navigator.userAgent;
if (window.ActiveXObject) {
var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
if (swf) {
flashVer = Number(swf.GetVariable('$version').split(' ')[1].replace(/,/g, '.').replace(/^(d+.d+).*$/, "$1"));
}
} else {
if (navigator.plugins && navigator.plugins.length > 0) {
var swf = navigator.plugins['Shockwave Flash'];
if (swf) {
var arr = swf.description.split(' ');
for (var i = 0, len = arr.length; i < len; i++) {
var ver = Number(arr[i]);
if (!isNaN(ver)) {
flashVer = ver;
break;
}
}
}
}
}
return flashVer;
}
var flashVer = getFlashVersion();
if (!isNaN(flashVer)) {
document.write('The current version of flash player:' + flashVer);
} else {
document.write('You don't have flash player installed');
}
I hope this article will be helpful to everyone's JavaScript programming.