简体   繁体   中英

Javascript code to redirect to another domain if flash player is installed

I actually have two websites on the same domain. say, for example

http://www.abc.com/flashsite

&

http://www.abc.com/htmlsite

flashsite contain the website that is fully flash based while the other is an html based with no flash. what i want is that, if somebody visits my url on http://www.abc.com , the javascript should first detect if the plugin is installed in his browser. if yes, then it should take me directly to the "flashsite" folder, and if not, then it should, by default, load the html website.

Thanks in advance.

I would suggest a index.html in your root which contains a link to the flash version and one to the html version. So users without javascript don't get stucked. In the onload-Event you call your script which handles the detection and redirection.

index.html like this

<html>
<head>
  <script type="text/javascript" src="yourscript.js"></script>
</head>
<body onload="yourfunction();">
  <a href="htmlversion">go to HTML-Version</a>
  <a href="flashversion">go to Flash-Version</a>
</body>
</html>

Javascript

You can detect if flash is installed via this script - http://code.google.com/p/swfobject/

A redirect is best done with window.location.replace(...); the rest should be straightforward ;)

Code "shamelessly" copied from http://www.adobe.com/support/flash/how/shock/javaplugs/javaplugs05.html

<script type="text/javascript">

<!-- use this comment tag to hide the enclosed code from old browsers.

//Look for a version of Internet Explorer that supports ActiveX (i.e., one that's
//running on a platform other than Mac or Windows 3.1) or a browser that supports
//the plugin property of the navigator object and that has Flash Player 2.0
//installed.

if ((navigator.appName == "Microsoft Internet Explorer" &&
    navigator.appVersion.indexOf("Mac") == -1 &&   navigator.appVersion.indexOf("3.1") == -1) ||

    (navigator.plugins && navigator.plugins["Shockwave Flash"])
                       || navigator.plugins["Shockwave Flash 2.0"]){

   //Load a pre-defined HTML page with Flash Player in it into the browser window.
    //window.location='flashed.html';
   alert ("flash plugin detected");
}
else {
    //Load a pre-defined HTML page without Flash Player into the browser window.
    //window.location='nonflashed.html';
   alert("flash plugin not detected");
}

// Close the comment tag. -->

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM