简体   繁体   English

使用JavaScript跳转到新的HTML页面

[英]Jumping to a new HTML page with JavaScript

In my HTML page, I need to check if Adobe Flash player is installed. 在我的HTML页面中,我需要检查是否安装了Adobe Flash Player。 If not, I want to automatically jump to another HTML page to tell the user that Flash player is required. 如果没有,我想自动跳转到另一个HTML页面,告诉用户需要Flash播放器。

I'm using JavaScript to check if the Flash player is available, using the ' JavaScript Flash detection library '. 我正在使用JavaScript来检查Flash播放器是否可用,使用“ JavaScript Flash检测库 ”。

The body of my HTML page looks like this: 我的HTML页面的主体如下所示:

<body>
    <script type="text/javascript"> 
    if(!FlashDetect.installed)
    {
        alert("Flash 9.0.115 is required to enjoy this site.");
    }
    </script>
    ...
    ...

The detection is working: I can see the alert, but I didn't find a way to jump to another HTML page. 检测工作正常:我可以看到警报,但我没有找到跳转到另一个HTML页面的方法。

Any hint? 任何提示?

Edit: There is something I didn't mention which seems to make a difference: the HTML pages are local pages (running from a CD-ROM), and I'd like to jump to an HTML page which is located in the current directory. 编辑:我没有提到的东西似乎有所不同:HTML页面是本地页面(从CD-ROM运行),我想跳转到位于当前目录中的HTML页面。

window.location.href = "http://stackoverflow.com";

For local files this should work if you know the relative path: (In your case this works.) 对于本地文件,如果您知道相对路径,这应该有效:(在您的情况下,这适用。)

window.location.href = "someOtherFile.html";

Maybe you could also do it absolute using this: (Not tested.) 也许你也可以使用这个绝对做到:(未经测试。)

window.location.pathname = "/path/to/another/file.html/";

The problem are the security measures of the browser vendors. 问题是浏览器供应商的安全措施。 Google has some good information about it. 谷歌有一些很好的信息

Be very wary of instant JavaScript redirects. 要非常警惕即时JavaScript重定向。 Flash detection scripts can be wrong(*) so it's best to allow the user to decide Flash-or-not themselves with some kind of manual override, or simply using fallback content. Flash检测脚本可能是错误的(*),因此最好允许用户通过某种手动覆盖或简单地使用后备内容来决定Flash或者不是自己。

Writing to location.href works but can "break the back button" - if the user presses Back and your page insta-redirects them forward a page again they're unlikely to be happy. 写入location.href有效,但可以“打破后退按钮” - 如果用户按下后退并且您的页面再次将页面重定向到一个页面,他们就不会感到高兴。 location.replace('...') avoids this problem. location.replace('...')避免了这个问题。

(* - there are two approaches to Flash detection, neither of them reliable. Creating a Flash instance and sniffing for it breaks with software like FlashBlock or just slow loading, and sniffing for plugins directly is not standardised and likely to break on more obscure platforms. Adobe's own code at http://www.adobe.com/devnet/flashplayer/articles/future_detection_print.html ends up resorting to sniffing the UA string, ugh.) (* - Flash检测有两种方法,它们都不可靠。创建Flash实例并嗅探它会破坏FlashBlock之类的软件或只是缓慢加载,直接嗅探插件并不是标准化的,可能会在更加模糊的平台上破解Adobe自己的代码http://www.adobe.com/devnet/flashplayer/articles/future_detection_print.html最终诉诸于嗅探UA字符串,呃。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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