Topic: How to detect JavaScript and Flash?

Currently, i use the following for detecting JavaScript:

<noscript>
        <meta http-equiv="refresh" content="0;URL=js.html" />
</noscript>

And after that, some JavaScript function to detect Flash, which i proudly copied from http://www.techmug.com/detect-javascrip … sh-enabled

<script type="text/javascript">
<!--
var MM_contentVersion = 9;
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.ShockwaveFlash." & MM_contentVersion)))n');
    document.write('</SCR' + 'IPT> n');
}

if ( MM_FlashCanPlay )
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="160" height="120">');
    document.write('<param name="movie" value="animation.swf">');
    document.write ('<param name="quality" value="high">');
    document.write ('<param name="wmode" value="transparent">');
    document.write('<embed src="animation.swf" width="160" height="120" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed></object>');
} else
{
    document.write('<a href="./"><img src="replaced-image.png" alt="Flash Plugin not Installed" border="0"></a>');

}
//-->

</script>

My problem, being not experienced in such questions, how to easily change my HTML output based on Flash being installed or not ...

For example, i have an image that opens a JavaScript gallery - i wish that line to open the SimpleViewer gallery instead, when Flash is enabled:

Code for JavaScript:

<td>Gallery 1:<a href="Polaroids.html" target="_blank"><img src="400/Polaroid/title.jpg" alt="Polaroid.html" border="no"></a></td>

Code for Flash:

<td>Gallery 1:<a href="index.html" target="_blank"><img src="400/Polaroid/title.jpg" alt="index.html" border="no"></a></td>

So, based on Flash being available or not either "Polaroids.html" or "index.html" should be opened ...
Such lines would appear several times in the calling page - having multiple galleries with the same situation.

And i cannot find an easy way to do this :-(

Any idea?

Last edited by SimpleUser (2012-03-06 21:47:08)

Re: How to detect JavaScript and Flash?

You can detect whether the user's browser has the required version of Flash for SimpleViewer using SWFObject and JavaScript.
Include 'swfobject.js' (http://code.google.com/p/swfobject/) in your page and include the following function:

<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
function checkFlash()
{
    var page="Polaroids.html";
    if (swfobject.hasFlashPlayerVersion("10.0.0"))
    {
        page="index.html";
    }
    return page;
}
</script>

Then your 'universal' link would look like the following:

<td>Gallery 1:<a href="#" target="_blank" onclick="this.href=checkFlash();"><img src="400/Polaroid/title.jpg" alt="index.html" border="no"></a></td>

When the user clicks on the 'title.jpg' image, if the browser has Adobe Flash Player 10.0.0 (or later) installed and enabled, the 'index.html' page will be opened, otherwise the 'Polaroids.html' page will be opened.

Steven Speirs
SimpleViewer Support Team.

Re: How to detect JavaScript and Flash?

Thank you very much!

Your support, BTW, is realy fantastic!
Thanks.

Do you also have an idea about how to used the above construction to have more than one such decision between JavaScript and Flash?

More concrete, i have HTML pages with lots of galleries - and would like to have clicking on them either open the Flash version with SimpleViewer, or the older version that just uses JavaScript instead.

But this would require to have more than of this one "#" parameters as href ... if i managed to make myself understandable smile

Maybe "#1", "#2" or something like this works?

<td>Gallery 1:<a href="#1" target="_blank" onclick="this.href=checkFlash();"><img src="400/Polaroid1/title.jpg" alt="index1.html" border="no"></a></td>
<td>Gallery 2:<a href="#2" target="_blank" onclick="this.href=checkFlash();"><img src="400/Polaroid2/title.jpg" alt="index2.html" border="no"></a></td>
<td>Gallery 3:<a href="#3" target="_blank" onclick="this.href=checkFlash();"><img src="400/Polaroid3/title.jpg" alt="index3.html" border="no"></a></td>
...

I will send you my stuff per mail, if i may smile

Re: How to detect JavaScript and Flash?

I now tried to solve this with multiple functions ... even if that feel cumbersome ...

Any more elegant solution would be appreciated, of course big_smile

<script type="text/javascript">
function gal1()
{
    var page="1_Polaroid.html"
    if (swfobject.hasFlashPlayerVersion("10.0.0"))
    {
        page="400/1/Polaroid/index.html";
    }
    return page;
}
function gal2()
{
    var page="2_Polaroid.html"
    if (swfobject.hasFlashPlayerVersion("10.0.0"))
    {
        page="400/2/Polaroid/index.html";
    }
    return page;
}
function gal3()
{
    var page="4_Polaroid.html"
    if (swfobject.hasFlashPlayerVersion("10.0.0"))
    {
        page="400/4/Polaroid/index.html";
    }
    return page;
}
</script>

Thanks for your hint!
smile

Last edited by SimpleUser (2012-03-07 23:29:17)

Re: How to detect JavaScript and Flash?

and would like to have clicking on them either open the Flash version with SimpleViewer, or the older version that just uses JavaScript instead

Since v2.1, SimpleViewer features Universal playback functionality. You can now embed a gallery using the embedding code found here and the gallery will be displayed using the Flash Player if it is available but will automatically switch to the HTML version on mobile devices and in browsers which do not have Flash Player installed and activated. There is no need to introduce any additional code. This may prove useful to you.

If you wish to continue along the current lines, you could pass two string parameters (a fallback URL to the JavaScript gallery and a URL to the Flash gallery) to the checkFlash() function from each individual link.
For example:

<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
function checkFlash(javascriptURL, flashURL)
{
    var page=javascriptURL;
    if (swfobject.hasFlashPlayerVersion("10.0.0"))
    {
        page=flashURL;
    }
    return page;
}
</script>

A sample link would look like this:

<td>Gallery 1:<a href="#" target="_blank" onclick="this.href=checkFlash('1_Polaroid.html', '400/1/Polaroid/index.html');"><img src="400/Polaroid1/title.jpg" alt="index1.html" border="no"></a></td>
Steven Speirs
SimpleViewer Support Team.

Re: How to detect JavaScript and Flash?

Steven, this works like a charm!
Thank you very much!
smile

As feedback on Universal Playback, this is a great option - but mostly for mobile device IMHO, as the interface is just too simple for a regular webbrowser on a desktop or laptop.

Also, there is one mistake (i think) in this: Images will not stop being enlarged when reaching their actual size, what means that on a regular webbrowser, images will be enlarged to fit the browser windows - or the complete screen - regardless of the setting in "imageScaleMode".

So, Universal Playback behaves like "imageScaleMode" set to "SCALE_UP" - which i feel is wrong.

Re: How to detect JavaScript and Flash?

So, Universal Playback behaves like "imageScaleMode" set to "SCALE_UP"

This is true. This is because, as you suggest, the Mobile Player was designed with small screens in mind.

Steven Speirs
SimpleViewer Support Team.