Detecting and embedding Flash within a web document is a surprisingly difficult task.
I was very disappointed with the quality and non-standards compliant markup generated from both SWFObject and Adobe's solutions. Additionally, my testing found Adobe's auto updater to be inconsistent and unreliable.
if(swfobject.hasFlashPlayerVersion("9.0.115"))
{
alert("You have the minimum required flash version (or newer)");
}
else
{
alert("You do not have the minimum required flash version");
}
Replace "9.0.115" with whatever minimum flash version you need. I chose 9.0.115 as an example because that's the version that added h.264 support.
If the visitor does not have flash, it will report a flash version of "0.0.0", so if you just want to know if they have flash at all, use:
if(swfobject.hasFlashPlayerVersion("1"))
{
alert("You have flash!");
}
else
{
alert("You do not flash :-(");
}
I know this is an old post, but I've been looking for a while and didn't find anything.
I've implemented the JavaScript Flash Detection Library.
It works very well and it is documented for quick use. It literally took me 2 minutes. Here is the code I wrote in the header:
<script src="Scripts/flash_detect.js"></script>
<script type="text/javascript">
if (!FlashDetect.installed) {
alert("Flash is required to enjoy this site.");
} else {
alert("Flash is installed on your Web browser.");
}
</script>
var a = !1,
b = "";
function c(d) {
d = d.match(/[\d]+/g);
d.length = 3;
return d.join(".")
}
if (navigator.plugins && navigator.plugins.length) {
var e = navigator.plugins["Shockwave Flash"];
e && (a = !0, e.description && (b = c(e.description)));
navigator.plugins["Shockwave Flash 2.0"] && (a = !0, b = "2.0.0.11")
} else {
if (navigator.mimeTypes && navigator.mimeTypes.length) {
var f = navigator.mimeTypes["application/x-shockwave-flash"];
(a = f && f.enabledPlugin) && (b = c(f.enabledPlugin.description))
} else {
try {
var g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"),
a = !0,
b = c(g.GetVariable("$version"))
} catch (h) {
try {
g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"), a = !0, b = "6.0.21"
} catch (i) {
try {
g = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), a = !0, b = c(g.GetVariable("$version"))
} catch (j) {}
}
}
}
}
var k = b;
a ? alert("flash version: " + k) : alert("no flash found");
If you just wanted to check whether flash is enabled, this should be enough.
function testFlash() {
var support = false;
//IE only
if("ActiveXObject" in window) {
try{
support = !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
}catch(e){
support = false;
}
//W3C, better support in legacy browser
} else {
support = !!navigator.mimeTypes['application/x-shockwave-flash'];
}
return support;
}
Note: avoid checking enabledPlugin, some mobile browser has tap-to-enable flash plugin, and will trigger false negative.
Using Google Closure compiler goog.require('goog.userAgent.flash') library I created this 2 functions.
boolean hasFlash()
Returns if browser has flash.
function hasFlash(){
var b = !1;
function c(a) {if (a = a.match(/[\d]+/g)) {a.length = 3;}}
(function() {
if (navigator.plugins && navigator.plugins.length) {
var a = navigator.plugins["Shockwave Flash"];
if (a && (b = !0, a.description)) {c(a.description);return;}
if (navigator.plugins["Shockwave Flash 2.0"]) {b = !0;return;}
}
if (navigator.mimeTypes && navigator.mimeTypes.length && (a = navigator.mimeTypes["application/x-shockwave-flash"], b = !(!a || !a.enabledPlugin))) {c(a.enabledPlugin.description);return;}
if ("undefined" != typeof ActiveXObject) {
try {
var d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");b = !0;c(d.GetVariable("$version"));return;
} catch (e) {}
try {
d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");b = !0;
return;
} catch (e) {}
try {
d = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), b = !0, c(d.GetVariable("$version"));
} catch (e) {}
}
})();
return b;
}
boolean isFlashVersion(version)
Returns if the flash version is greater than provided version
function isFlashVersion(version) {
var e = String.prototype.trim ? function(a) {return a.trim()} : function(a) {return /^[\s\xa0]*([\s\S]*?)[\s\xa0]*$/.exec(a)[1]};
function f(a, b) {return a < b ? -1 : a > b ? 1 : 0};
var h = !1,l = "";
function m(a) {a = a.match(/[\d]+/g);if (!a) {return ""}a.length = 3;return a.join(".")}
(function() {
if (navigator.plugins && navigator.plugins.length) {
var a = navigator.plugins["Shockwave Flash"];
if (a && (h = !0, a.description)) {l = m(a.description);return}
if (navigator.plugins["Shockwave Flash 2.0"]) {h = !0;l = "2.0.0.11";return}
}
if (navigator.mimeTypes && navigator.mimeTypes.length && (a = navigator.mimeTypes["application/x-shockwave-flash"], h = !(!a || !a.enabledPlugin))) {l = m(a.enabledPlugin.description);return}
if ("undefined" != typeof ActiveXObject) {
try {
var b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");h = !0;l = m(b.GetVariable("$version"));return
} catch (g) {}
try {
b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");h = !0;l = "6.0.21";return
} catch (g) {}
try {
b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"), h = !0, l = m(b.GetVariable("$version"))
} catch (g) {}
}
})();
var n = l;
return (function(a) {
var b = 0,g = e(String(n)).split(".");
a = e(String(a)).split(".");
for (var p = Math.max(g.length, a.length), k = 0; 0 == b && k < p; k++) {
var c = g[k] || "",d = a[k] || "";
do {
c = /(\d*)(\D*)(.*)/.exec(c) || ["", "", "", ""];d = /(\d*)(\D*)(.*)/.exec(d) || ["", "", "", ""];
if (0 == c[0].length && 0 == d[0].length) {break}
b = f(0 == c[1].length ? 0 : parseInt(c[1], 10), 0 == d[1].length ? 0 : parseInt(d[1], 10)) || f(0 == c[2].length, 0 == d[2].length) || f(c[2], d[2]);c = c[3];d = d[3]
} while (0 == b);
}
return 0 <= b
})(version)
}