473,395 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Javascript Flash Detector

Hey everyone, i've been playing around with trying to get some scripts to work with detecting whether flash player is installed on your computer or not. I found a flash detection kit on the adobe site which had a client side detection method using javascript.

Basically what im trying to get it to do is if flash player is installed, use the style property display="none" to hide my static content, and if flash is not installed hide the flash content using display="none".

Here's my page.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Flash Test</title>
  6. </head>
  7.     <script src="flash_check.js" language="javascript" type="text/javascript"></script>
  8.     <script language="JavaScript" type="text/javascript">
  9.         var requiredMajorVersion = 9;
  10.         var requiredMinorVersion = 0;
  11.         var requiredRevision = 0;
  12.     </script>
  13. <body>
  14.     <script language="JavaScript" type="text/javascript">
  15.         var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  16.         if (hasReqestedVersion) {
  17.             document.getElementById("html").style.display="none";
  18.         } else {
  19.             document.getElementById("flash").style.display="none";
  20.         }
  21.     </script>
  22.     <div id="html">
  23.         This is the Static Content
  24.         <br />
  25.     </div>
  26.     <div id="flash">
  27.         This is the Flash Content
  28.         <br />
  29.     </div>
  30. </body>
  31. </html>
  32.  
This is the js file that Adobe included with there detection pack. I haven't changed anything in this file.

Expand|Select|Wrap|Line Numbers
  1. // Flash Player Version Detection - Rev 1.5
  2. // Detect Client Browser type
  3. // Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
  4. var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
  5. var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
  6. var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
  7.  
  8. function ControlVersion()
  9. {
  10.     var version;
  11.     var axo;
  12.     var e;
  13.  
  14.     // NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
  15.  
  16.     try {
  17.         // version will be set for 7.X or greater players
  18.         axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
  19.         version = axo.GetVariable("$version");
  20.     } catch (e) {
  21.     }
  22.  
  23.     if (!version)
  24.     {
  25.         try {
  26.             // version will be set for 6.X players only
  27.             axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
  28.  
  29.             // installed player is some revision of 6.0
  30.             // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
  31.             // so we have to be careful. 
  32.  
  33.             // default to the first public version
  34.             version = "WIN 6,0,21,0";
  35.  
  36.             // throws if AllowScripAccess does not exist (introduced in 6.0r47)        
  37.             axo.AllowScriptAccess = "always";
  38.  
  39.             // safe to call for 6.0r47 or greater
  40.             version = axo.GetVariable("$version");
  41.  
  42.         } catch (e) {
  43.         }
  44.     }
  45.  
  46.     if (!version)
  47.     {
  48.         try {
  49.             // version will be set for 4.X or 5.X player
  50.             axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
  51.             version = axo.GetVariable("$version");
  52.         } catch (e) {
  53.         }
  54.     }
  55.  
  56.     if (!version)
  57.     {
  58.         try {
  59.             // version will be set for 3.X player
  60.             axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
  61.             version = "WIN 3,0,18,0";
  62.         } catch (e) {
  63.         }
  64.     }
  65.  
  66.     if (!version)
  67.     {
  68.         try {
  69.             // version will be set for 2.X player
  70.             axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
  71.             version = "WIN 2,0,0,11";
  72.         } catch (e) {
  73.             version = -1;
  74.         }
  75.     }
  76.  
  77.     return version;
  78. }
  79.  
  80. // JavaScript helper required to detect Flash Player PlugIn version information
  81. function GetSwfVer(){
  82.     // NS/Opera version >= 3 check for Flash plugin in plugin array
  83.     var flashVer = -1;
  84.  
  85.     if (navigator.plugins != null && navigator.plugins.length > 0) {
  86.         if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
  87.             var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
  88.             var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;            
  89.             var descArray = flashDescription.split(" ");
  90.             var tempArrayMajor = descArray[2].split(".");
  91.             var versionMajor = tempArrayMajor[0];
  92.             var versionMinor = tempArrayMajor[1];
  93.             if ( descArray[3] != "" ) {
  94.                 tempArrayMinor = descArray[3].split("r");
  95.             } else {
  96.                 tempArrayMinor = descArray[4].split("r");
  97.             }
  98.             var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  99.             var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
  100.         }
  101.     }
  102.     // MSN/WebTV 2.6 supports Flash 4
  103.     else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
  104.     // WebTV 2.5 supports Flash 3
  105.     else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
  106.     // older WebTV supports Flash 2
  107.     else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
  108.     else if ( isIE && isWin && !isOpera ) {
  109.         flashVer = ControlVersion();
  110.     }    
  111.     return flashVer;
  112. }
  113.  
  114. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  115. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
  116. {
  117.     versionStr = GetSwfVer();
  118.     if (versionStr == -1 ) {
  119.         return false;
  120.     } else if (versionStr != 0) {
  121.         if(isIE && isWin && !isOpera) {
  122.             // Given "WIN 2,0,0,11"
  123.             tempArray         = versionStr.split(" ");     // ["WIN", "2,0,0,11"]
  124.             tempString        = tempArray[1];            // "2,0,0,11"
  125.             versionArray      = tempString.split(",");    // ['2', '0', '0', '11']
  126.         } else {
  127.             versionArray      = versionStr.split(".");
  128.         }
  129.         var versionMajor      = versionArray[0];
  130.         var versionMinor      = versionArray[1];
  131.         var versionRevision   = versionArray[2];
  132.  
  133.             // is the major.revision >= requested major.revision AND the minor version >= requested minor
  134.         if (versionMajor > parseFloat(reqMajorVer)) {
  135.             return true;
  136.         } else if (versionMajor == parseFloat(reqMajorVer)) {
  137.             if (versionMinor > parseFloat(reqMinorVer))
  138.                 return true;
  139.             else if (versionMinor == parseFloat(reqMinorVer)) {
  140.                 if (versionRevision >= parseFloat(reqRevision))
  141.                     return true;
  142.             }
  143.         }
  144.         return false;
  145.     }
  146. }
  147.  
  148. function AC_AddExtension(src, ext)
  149. {
  150.   if (src.indexOf('?') != -1)
  151.     return src.replace(/\?/, ext+'?'); 
  152.   else
  153.     return src + ext;
  154. }
  155.  
  156. function AC_Generateobj(objAttrs, params, embedAttrs) 
  157.     var str = '';
  158.     if (isIE && isWin && !isOpera)
  159.     {
  160.           str += '<object ';
  161.           for (var i in objAttrs)
  162.               str += i + '="' + objAttrs[i] + '" ';
  163.           for (var i in params)
  164.              str += '><param name="' + i + '" value="' + params[i] + '" /> ';
  165.           str += '></object>';
  166.     } else {
  167.           str += '<embed ';
  168.           for (var i in embedAttrs)
  169.               str += i + '="' + embedAttrs[i] + '" ';
  170.           str += '> </embed>';
  171.     }
  172.     document.write(str);
  173.  
  174.  }
  175.  
  176. function AC_FL_RunContent(){
  177.   var ret = 
  178.     AC_GetArgs
  179.     (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
  180.      , "application/x-shockwave-flash"
  181.     );
  182.   AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
  183. }
  184.  
  185. function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  186.   var ret = new Object();
  187.   ret.embedAttrs = new Object();
  188.   ret.params = new Object();
  189.   ret.objAttrs = new Object();
  190.   for (var i=0; i < args.length; i=i+2){
  191.     var currArg = args[i].toLowerCase();    
  192.  
  193.     switch (currArg){    
  194.       case "classid":
  195.         break;
  196.       case "pluginspage":
  197.         ret.embedAttrs[args[i]] = args[i+1];
  198.         break;
  199.       case "src":
  200.       case "movie":    
  201.         args[i+1] = AC_AddExtension(args[i+1], ext);
  202.         ret.embedAttrs["src"] = args[i+1];
  203.         ret.params[srcParamName] = args[i+1];
  204.         break;
  205.       case "onafterupdate":
  206.       case "onbeforeupdate":
  207.       case "onblur":
  208.       case "oncellchange":
  209.       case "onclick":
  210.       case "ondblClick":
  211.       case "ondrag":
  212.       case "ondragend":
  213.       case "ondragenter":
  214.       case "ondragleave":
  215.       case "ondragover":
  216.       case "ondrop":
  217.       case "onfinish":
  218.       case "onfocus":
  219.       case "onhelp":
  220.       case "onmousedown":
  221.       case "onmouseup":
  222.       case "onmouseover":
  223.       case "onmousemove":
  224.       case "onmouseout":
  225.       case "onkeypress":
  226.       case "onkeydown":
  227.       case "onkeyup":
  228.       case "onload":
  229.       case "onlosecapture":
  230.       case "onpropertychange":
  231.       case "onreadystatechange":
  232.       case "onrowsdelete":
  233.       case "onrowenter":
  234.       case "onrowexit":
  235.       case "onrowsinserted":
  236.       case "onstart":
  237.       case "onscroll":
  238.       case "onbeforeeditfocus":
  239.       case "onactivate":
  240.       case "onbeforedeactivate":
  241.       case "ondeactivate":
  242.       case "type":
  243.       case "codebase":
  244.       case "id":
  245.         ret.objAttrs[args[i]] = args[i+1];
  246.         break;
  247.       case "width":
  248.       case "height":
  249.       case "align":
  250.       case "vspace": 
  251.       case "hspace":
  252.       case "class":
  253.       case "title":
  254.       case "accesskey":
  255.       case "name":
  256.       case "tabindex":
  257.         ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
  258.         break;
  259.       default:
  260.         ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
  261.     }
  262.   }
  263.   ret.objAttrs["classid"] = classid;
  264.   if (mimeType) ret.embedAttrs["type"] = mimeType;
  265.   return ret;
  266. }
  267.  
Any help would be appreaciated. :)
Mar 7 '08 #1
1 2694
acoder
16,027 Expert Mod 8TB
Check that the Adobe detection script gives the correct version number, etc. or if uninstalled, what output is given. Based on that, you can use the script to show/hide content.
Mar 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joh | last post by:
Hello, (sorry long) i think i have missed something in the code below, i would like to design some kind of detector with python, but i feel totally in a no way now and need some advices to...
5
by: Mika S. | last post by:
Hi, How can I detect if the Flash plugin is installed? Should be working with the most common browsers and environments. Thanks, Mika
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
1
by: bin_P19 P | last post by:
the code i have got is as follows and now im stuck <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Shopping...
5
by: J | last post by:
Hi All, I have a quick question, I am making a little script that shows users how easy it is to have there clipboards read. I would like to capture my users clipboard (plain text only) and then...
3
by: sqpost | last post by:
Hi, I have a web-application project which requires interactive User Interfaces. It is more like a web based xml content editor. I have seen a few javascript based text editors but not much flash...
5
by: Lalit | last post by:
Hi Group, I have discovered a technique by which we can be able to detect if a particular font is present in a user's machine. Below is a brief info about the script. You can find more info at...
2
by: spiralof5 | last post by:
Hi. I must first say I'm not an experienced scripter. Here's my problem and how far I am so far. I struggled for awhile to get the browser to fill most of it with my flash movie and keep it...
26
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.