2011-02-18 53 views
0

如果用戶沒有安裝Flash,我希望在我的Flex應用程序中重定向到HTML頁面。我注意到在Flash生成的HTML中它有:如果Flash未安裝,如何重定向到HTML頁面?

 <div id="flashContent"> 
      <p> 
       To view this page ensure that Adobe Flash Player version 
       10.0.0 or greater is installed. 
      </p> 
      <script type="text/javascript"> 

       var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://"); 
       document.write("<a href='http://www.adobe.com/go/getflashplayer'><img src='" 
           + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>"); 
      </script> 
     </div> 

其中顯示關於沒有閃光燈的一般消息。

我知道如果Flash不存在,我可以將HTML顯示出來,但如果不需要,我不想加載HTML(當Flash安裝時),所以我認爲最好的方法是重定向如果flash不存在,則轉到HTML頁面。

如何在Flex中做到這一點?

回答

2

您將無法在Flex中執行此操作,因爲如果用戶沒有正確的Flash播放器版本,您的應用程序將無法加載。所以你最好的選擇是修改index.template.html文件。您尚未指定您正在使用的Flex版本,模板文件可能在版本4和版本3之間不同。

Flex 3有以下JS代碼來檢測用戶是否具有良好的Flash Player版本:

// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65) 
var hasProductInstall = DetectFlashVer(6, 0, 65); 

// Version check based upon the values defined in globals 
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); 

if (hasProductInstall && !hasRequestedVersion) { 

//狙擊

} else if (hasRequestedVersion) { 

//狙擊

} else { // flash is too old or we can't detect the plugin 

而且它在這最後別的,你會想將您的JS代碼重定向,類似:

window.location.replace('otherpage.html'); 

你的模板文件應該有與此類似。

更多關於JS重定向 - http://andylangton.co.uk/articles/javascript/javascript-redirect-scripts/

的Flex 4

首先禁用表達從項目屬性設置 - >下的HTML包裝Flex編譯器。 警告:這將覆蓋你的html模板文件夾,所以你對這些文件的修改將會丟失。當你這樣做時,你應該得到一個確認彈出窗口。

然後在文本編輯器中打開html-template/swfobject.js。前往路線693 - 它應該是剛下其他的功能的embedSWF「顯示替代內容」 - 和評論,並添加,或者只是將其替換爲:

window.location.replace('http://mydomain/noflash.html'); 

做一個乾淨的構建你保存文件後。

這是做這件事最直接的方法。還有一種更優雅的方式,您不需要修改swfobject.js,而是使用index.template.html,但需要編寫更多代碼。

請注意在Flex編譯器中有一些設置會覆蓋你的html模板文件夾,撤消你對文件中所做的任何更改。

+0

Thanks @ bug-a-lot.I嘗試了上面的代碼,但它沒有奏效!也許是因爲我使用Flex 4? – Tam 2011-02-18 18:37:05

相關問題