Bookmark and Share

Tuesday, August 03, 2010

How to replace Flash with an Image for IPad/IPhone & disabled flash browsers

If your web site users are using IPad or IPhone or simply if they disabled flash on their browser you need to replace the ugly imageicon with a beautiful image.

Here is the magic script, copied from the web site http://www.kirupa.com/developer/mx/detection.htm, the script shows the swf flash or replaces it with an image if Flash is not supported.

<SCRIPT LANGUAGE=JavaScript1.1>
<!--
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.ShockwaveFlash." & MM_contentVersion)))\n');
document.write('</SCR' + 'IPT\> \n');
}
if ( MM_FlashCanPlay ) {
document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ');
document.write(' ID="script" WIDTH="300" HEIGHT="200" ALIGN="">');
document.write(' <PARAM NAME=movie VALUE="script.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> ');
document.write(' <EMBED src="script.swf" quality=high bgcolor=#FFFFFF ');
document.write(' swLiveConnect=FALSE WIDTH="300" HEIGHT="200" NAME="script" ALIGN=""');
document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
document.write(' </EMBED>');
document.write(' </OBJECT>');
} else{
document.write('<IMG SRC="script.gif" WIDTH="300" HEIGHT="200" usemap="#script" BORDER=0>');
}
//-->
</SCRIPT><NOSCRIPT><IMG SRC="script.gif" WIDTH="300" HEIGHT="200" usemap="#script" BORDER=0></NOSCRIPT>

 

Replace the script.swf file name with your flash and replace the script.gif image with your replacement image name.


This script is tested and working!


 

17 comments:

  1. Many thanks for sharing this, was really helpful!

    If you go to use this just be sure to spot, and change the image dimensions to whatever you need.

    ReplyDelete
  2. Hi

    Where do you place this script?

    ReplyDelete
  3. Hi,

    thanks for the script! Is it possible to add a link to the image? If yes how should I define this? Can I just add link tags around the im tag?

    ReplyDelete
  4. Hello,
    look at the latest document.write...
    just surround the IMG tag with an href tag... that's all.

    ReplyDelete
  5. Where do I place this script? In the Head? After or before the Flash Code?

    ReplyDelete
  6. This works great... except... the flash now stays on top of all layers. Even with z-index set at 1 and an image inside a div at z-index set at 2, the flash still shows on top.

    anyway to fix this?

    thanks

    ReplyDelete
  7. Hi Mo, thanks for using my blog!
    The flash zindex problem is known by the community, try these links, they will guide you to the solution:
    http://kb2.adobe.com/cps/155/tn_15523.html and
    http://forums.precharge.com/website-design/420-z-index-stack-order-problem.html

    You need to work on flash properties.

    Hope it helps!

    ReplyDelete
  8. I used this script with a redirection to a non flash device friendly website as an else command at the end instead of an image.

    Here's the final code:

    else{
    window.location.replace("http://www.script.domain extension");
    }

    Just replace the website domain and you're there.

    Thanks for the initial excellent code, a big help!

    ReplyDelete
  9. Thank you for your code, I appreciate it!

    ReplyDelete
  10. For me, this code works for FireFox, Chrome, and Opera. When viewing in Safari on iPhone and iPad, it also works (displays image).

    Internet Explorer however, displays the alternate image, even though flash is installed, and displays the swf normally without this code.

    Thoughts?

    ReplyDelete
  11. Never mind! Found the problem. Internet Explorer was reporting latest Flash module... but wasn't loading the addin.

    Thank you IE, you consistently make my life happier.

    ReplyDelete
  12. Thank for this post! Very helpful!

    ReplyDelete
  13. Many thanks, this has cleared up a issue for one of our clients who wants to use a flash logo but appear on iPhone/iPads

    ReplyDelete
  14. You are welcome, I'm happy to be useful!

    ReplyDelete
  15. Where Do you put this Script? and mine is a slide show in flash will this still work ?

    ReplyDelete
  16. Hi There Where exactly do I put this code into my php file I assume ? and I have got a carousal slide show on my front page in flash, will this still work for me ? As looks bad with no image on iphone ipads etc

    ReplyDelete
  17. Put the script in the HEAD section of your php file, it will be executed on the client side.
    Why don't you use a Javascript carousel? It's compatible with Iphone/Ipad and there are a lot out of there.

    ReplyDelete