如果未安装Flash,如何重定向到HTML页面?

时间:2011-02-18 08:08:09

标签: flex redirect

如果用户没有安装Flash,我希望在我的Flex应用中重定向到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中执行此操作?

1 个答案:

答案 0 :(得分:2)

您将无法在Flex中执行此操作,因为如果用户没有正确的Flash播放器版本,您的应用程序将无法加载。因此,最好的办法是修改index.template.html文件。您尚未指定正在使用的Flex版本,版本4和3之间的模板文件可能不同。

Flex 3 有以下JS代码来检测用户是否拥有良好的Flashplayer版本:

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

首先从项目属性禁用快速安装 - &gt; HTML包装器下的Flex编译器。 警告:这将覆盖您的html-template文件夹,因此您对这些文件的所有修改都将丢失。当你这样做时,你应该得到一个确认弹出窗口。

然后在文本编辑器中打开html-template / swfobject.js。转到第693行 - 它应该位于函数embedSWF中的“显示替代内容”之下 - 并对其进行注释并添加,或者只需将其替换为:

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

保存文件后执行干净的构建。

这是最简单的方法。还有一种更优雅的方式,你不修改swfobject.js而是修改index.template.html,但需要更多代码编写。

请注意,Flex Compiler下的某些设置会覆盖您的html-template文件夹,撤消您对其中的文件所做的任何更改。