The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 4 of 4

Thread: Javascript Flash Detection + CSS

  1. #1

    Javascript Flash Detection + CSS

    Hello all, I've been using the Kirupa tuts for while but Ive got one that I need some help to adapt. I want to adapt the Kirupa flash detection script from this page: http://www.kirupa.com/developer/mx/detection.htm (near the bottom) whereby if the flash plugin is installed the flash element is shown, if not an image is used instead

    *What I want to do is say - If the flash plugin is installed change the CSS background-color of an elements ID, if not installed change the CSS background-color of different elements ID.

    -I figure it has something to do with the JavaScript 'getElementbyID' but being a bit of a Javascript muppet Ive only had limited success..

    -I know for example that Javascript refers to the CSS properties slightly differently: http://codepunk.hardwar.org.uk/css2js.htm

    This is what I have written BUT it works only in Firefox, not IE... how should I write this properly?
    ------

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Flash Detection changing the CSS Style</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <SCRIPT LANGUAGE=JavaScript1.1>
    <!--
    function test() {
    var MM_contentVersion = 6;
    var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
    if ( plugin ) {
    var words = navigator.plugins["Shockwave Flash"].description.split(" ");
    for (var i = 0; i < words.length; ++i)
    {
    if (isNaN(parseInt(words[i])))
    continue;
    var MM_PluginVersion = words[i];
    }
    var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
    }
    else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0
    && (navigator.appVersion.indexOf("Win") != -1)) {
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
    document.write('on error resume next \n');
    document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFla sh." & MM_contentVersion)))\n');
    document.write('</SCR' + 'IPT\> \n');
    }
    if ( MM_FlashCanPlay ) {
    document.getElementById("hasflash").style.backgrou ndColor="yellow";
    } else{
    document.getElementById("noflash").style.backgroun dColor="yellow";
    }
    }
    //-->
    </SCRIPT>

    <style>
    #hasflash {
    font-size:26px;
    font-family:Arial, Helvetica, sans-serif;
    }
    #noflash {
    font-size:26px;
    font-family:Arial, Helvetica, sans-serif;
    }
    </style>

    </head>

    <body onload="test()">
    <div id="hasflash">Has flash</div>
    <div id="noflash">No flash</div>
    </body>
    </html>
    -------------------

    Cheers, Richter

  2. #2
    Anyone? Maybe I shouldve used a sexier title than just 'flash detection blah blah' PLEASE anyone who knows anything about changing CSS ID's / classes from a Javascript if/else statement?

  3. #3

    Javascript problem

    The Error is you have an I.D.10.T error. All signs and evidence appear to point towards the coder...

    I told you, COM.....C++....Applet..... not J/Script

    Your 100% sure your browser just doesn't have Javascript Disabled?

    Maybe you got a freeze mouse when doing your coding??




    Tonking

  4. #4
    ok world we can obviously ignore that last post..
    ------
    Now seriously here is a link to what I have: http://www.untitled-project.com/jobt...lash-test2.htm

    Please view in Firefox first to see what Im trying to do - it works - view source to see the code (as posted previously).

    BUT in IE it falls over. Now the kirupa code (from the bottom of this page http://www.kirupa.com/developer/mx/detection.htm ) seems to fall over when I put it in a function and call it from the <body onload. It returns 'undefined' for the variable MM_FlashCanPlay as soon as it is put inside the function and run. I note that javascript is writing out some vbscript here for the benefit of IE but I really have no idea why. I think that the value of MM_FlashCanPlay can not properly be set then, but again I dont know why. View source in IE to see what it is writing out... strange to me.

    Please can someone have a look at this.. Im new to this forum and if its all out of your leagues just let me know so I can seek out some help somewhere else. I was hoping that since I found the tutorial on Kirupa there might be help here too.

    Cheers!
    Richter

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012