Detect Javascript and Flash Enabled

Javascript and Flash are super tools to enhance the usability of your website. You put a lot of efforts to create beautiful form validation and an attractive flash animation. But all the efforts are ruined when the visitor of your website has disabled Javascript or does not have flash plugin installed. Here I’ll provide you a little solution to escape from this problem.

First Tactic – Detect Javascript Enabled

Our first step is to detect whether visitor has Javascript enabled or not. If Javascript is not enable, we will redirect user to an error/instruction page (I create a seperate page where I give instructions to visitor that how to enable Javascript in his/her browser).

Put below code just after the <head> tag in your web page:

<noscript>
<meta http-equiv="refresh" content="0;URL=error-javascript.php" />
</noscript>

Above code is executed if Javascript is disabled and redirect user to error-javascript.php. We are using <meta> tag for redirection. If Javascript is not disabled, above code will not be executed.

Second Tactic- Detect Flash Plugin Installed

There is a Javascript solution to detect Flash Plugin Installed and replace Flash animation with your custom message. In order to accomplish the said task you need to place below Javascript instead of your normal embedded code:

<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>

Above code detect for Version 9 or greater version of flash plugin. If flash plugin is detected it displays flash animation (animation.swf) else it displays an image (replaced-image.png) instead of flash animation. In the place of image you can write more text and instructions. Everything is upto on you.

Don’t forget to share the post on your favorite website. It may also help someone somewhere.

written by +

I believe we learn everyday a new thing and add another experience in our life. Same apply for me…so I share my experiences in the field of web development and design with the hope it will be useful for someone.
Related Posts

19 Responses to "Detect Javascript and Flash Enabled"

  1. S Shahzad Alam says:

    Dear Fraz, Thank You.

  2. Shahzaib says:

    mashaAllah I really like your post but tell me can we define our page beside error-javascript.php???

  3. Fraz Ahmed says:

    Ya you can use any name for error page.

  4. Geoff Murrey says:

    Wouldn’t redirecting based solely on JavaScript being disabled affect indexing of your contents by Google etc. therefore severely affecting your SEO?
    This could be overcome by checking HTTP_USER_AGENT to determine if browser/bot before serving the page.

    Even with this I think that telling users to do something is not going to get the reaction you want – if they have disabled Javascript, they are highly unlikely to enable it just to see your site, therefore an opportunity missed.

    Always have a degradation option.

  5. Fraz Ahmed says:

    Using HTTP_USER_AGENT is a good idea. But still some people may find it useful because it is quick and it is easy :)

  6. Djohariah says:

    Good work

  7. erotic art says:

    Just thought i would comment and say neat design, did you code it yourself? Looks great.

  8. cut the rope says:

    I like Your Article about Detect Javascript and Flash Enabled | Tech Mug Perfect just what I was looking for! .

  9. lee min ho says:

    Heya i am for the first time here. I found this board and I find It truly useful & it helped me out a lot. I hope to give something back and aid others like you aided me.

  10. beyin tümörü belirtileri says:

    Pretty section of content. I just stumbled upon your site and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I’ll be subscribing to your augment and even I achievement you access consistently quickly.

  11. Detect Javascript and Flash Enabled | Techmug | Web Development & Solution Tutorials says:

    [...] Read More Follow On Teachmug Posted in: Flash, General, Java Script   Tags: animation, Detect Javascript, Flash, Flash Enabled, html, Javascript, plugin, swf, tactic [...]

  12. rtyecript says:

    I really liked the article, and the very cool blog

  13. Terry Munter says:

    Thanks for the article, how can I make is so that I receive an email when you make a fresh post?

  14. Lang Dinos says:

    Excellent informations indeed. I have been awaiting for this tips. Thanks;)

  15. Блог о путешествиях says:

    Thx for this great information that you are sharing with us!!!

  16. A.J. says:

    Thanks for the great code! It works great, although in IE8 I’m getting a Javascript error, pointing to the line on which I close the last script tag. It says “Expected end of line”. Any ideas?

  17. Riccardo says:

    Hi, thanks for your code, which works perfectly on Safari, Firefox and Chrome.
    I have problems with Internet Explorer, version 8, with Flash Player activeX plugin version 11.1 installed.
    Even if the plugin is present, your code redirects the visitor to the my noflash page.
    Same site with traditional embedding code is clearly visible.
    My HTML code is W3C validated.
    Any suggestion?

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge
© Copyright - Tech Mug