Jumping to a new HTML page with JavaScript

后端 未结 2 1061
[愿得一人]
[愿得一人] 2021-01-12 14:42

In my HTML page, I need to check if Adobe Flash player is installed. If not, I want to automatically jump to another HTML page to tell the user that Flash player is required

相关标签:
2条回答
  • 2021-01-12 15:10

    Be very wary of instant JavaScript redirects. 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.

    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.replace('...') avoids this problem.

    (* - 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.)

    0 讨论(0)
  • 2021-01-12 15:31
    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.

    0 讨论(0)
提交回复
热议问题