473,848 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Flash Detector

1 New Member
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 2735
acoder
16,027 Recognized Expert Moderator MVP
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
2336
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 advance :( data = "it is an <atag> example of the kind of </atag> data it must handle and another kind of data".split(" ")
5
11390
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
5616
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 fallacy built on the assumption of mythical infinite all powerfull machines. In reality we deal with finite machines that are capable of two states in a loop, they either terminate, or repeat themselves. In the mythical halting problem scenario...
1
6095
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 Cart</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="StyleSheet" href="css/style.css" type="text/css">
5
1544
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 AUTOMATICALLY send them to a page displaying there contents, I want to get the +content+ put into a $content vairiable for easier manipulation in PHP. As javascript is client side and PHP serverside, i need to submit the form
3
2073
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 based ones. I dont have much experience on neither of the technologies so I have to spent some time to develop my skills on them (your suggestions are wellcome:) my questions are: 1. Is JavaScript and the today's internet users's enveronment...
5
2817
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 my website http://www.lalit.org/lab/fontdetect.php "Javascript/CSS Font Detector" This Javascript code can be used to guess if a particular font is
2
1804
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 proportional if the user chooses to size up or size down. This pretty much takes care of the browser size complications. Here is original script and it works. But now I have few problems after this. CODE#1 <!-- masked --> <html> <head>...
26
3923
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 almost no posts from the last 3 years: http://groups.google.com/group/comp.lang.javascript/search?group=comp.lang.javascript&q=how+to+play+a+sound+with+Javascript&qt_g=Search+this+group Even after sorting by date, there don't appear any...
0
9738
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11001
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10722
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10348
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7894
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5919
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4137
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.