display flash if you have it, image if not

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

display flash if you have it, image if not

Post by Burrito »

my boss just asked me to create a page that will display a flash animiation but should display a static image if the user's browser doesn't have flash installed.

I'm pretty sure it's not so simple as just putting both 'elements' on the page...but I'm not sure about the flash detection. I wrote a script a few years back that reported several browser settings (flash being one of them), but that was a pretty JS heavy endeavor....I'd like to avoid that if possible.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I don't know about the latest Flash release but MX had an export/publish option that created some JS to do just that. Here's what it looks like.


Code: Select all

<SCRIPT LANGUAGE=JavaScript1.1 type="text/javascript">
<!--
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="songmovie" WIDTH="150" HEIGHT="30" ALIGN="">');
	document.write(' <PARAM NAME=movie VALUE="songmovie.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF>  '); 
	document.write(' <EMBED src="songmovie.swf" quality=high bgcolor=#FFFFFF  ');
	document.write(' swLiveConnect=FALSE WIDTH="150" HEIGHT="30" NAME="songmovie" 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="songmovie.gif" WIDTH="150" HEIGHT="30" usemap="#songmovie" BORDER=0>');
}
//-->
</SCRIPT>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

awesome thank you neophyte.
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

Post by mojeIme »

This looks cool, but i think that those who dont have flash installed ,are not worth of this.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

This looks cool, but i think that those who dont have flash installed ,are not worth of this.
Personally, I have Flash disabled by default for all sites.

I also have Javascript disabled (you may want to add <noscript>).
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post by JAB Creations »

Code: Select all

<object>
 <param></param>
 <param></param>
 <param></param>
 <element>Alternative content here.</element>
</object>
So if you want an image in place of a Flash object if the Flash fails or is not installed...

Code: Select all

<object>
 <param></param>
 <param></param>
 <param></param>
 <img alt="" src="" title="" />
</object>
This is not well known but it is the proper way to do so. Disable Flash and reload your page with this code (modded to the way you want of course).

Best of luck!
Post Reply