簡體   English   中英

如果安裝了Flash播放器,則重定向到另一個域的Javascript代碼

[英]Javascript code to redirect to another domain if flash player is installed

我實際上在同一個域上有兩個網站。 比如說

http://www.abc.com/flashsite

http://www.abc.com/htmlsite

flashsite包含完全基於flash的網站,而另一個是基於html但沒有flash的網站。 我想要的是,如果有人在http://www.abc.com上訪問我的網址,javascript應首先檢測插件是否安裝在他的瀏覽器中。 如果是,那么它應該直接帶我到“flashsite”文件夾,如果沒有,那么默認情況下它應該加載html網站。

提前致謝。

我建議你的root中有一個index.html,它包含一個指向flash版本的鏈接和一個指向html版本的鏈接。 所以沒有javascript的用戶不會被卡住。 在onload-Event中,您可以調用處理檢測和重定向的腳本。

index.html就是這樣

<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

您可以通過此腳本檢測是否安裝了Flash - http://code.google.com/p/swfobject/

重定向最好用window.location.replace(...); 其余應該是直截了當的;)

代碼“無恥地”從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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM