Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jumping to a new HTML page with JavaScript

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.

I'm using JavaScript to check if the Flash player is available, using the 'JavaScript Flash detection library'.

The body of my HTML page looks like this:

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

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.

like image 542
Jérôme Avatar asked Jan 14 '09 09:01

Jérôme


People also ask

How do you go to a new page in JavaScript?

JavaScript window. To navigate to a new URL, use the location object from the Browser's History API. The session history lets you reassign the location object to a new URL or use the href property on that same object. The syntax for this approach is: window.

How do I move one HTML page to another using JavaScript?

Answer: Use the JavaScript window. location Propertylocation property to make a page redirect, you don't need any jQuery for this. If you want to redirect the user from one page to another automatically, you can use the syntax window. location. replace("page_url") .

How do you jump to a specific section in JavaScript?

A simple and modern way to do this would be like this: document. getElementById("jump_to_this_location").

How do I open a new HTML file in JavaScript?

use location. href = "page2. html"; if you want to open a page in the same window. The OP is asking for a new tab, not the current page nor popup.


2 Answers

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.

like image 75
Georg Schölly Avatar answered Oct 21 '22 07:10

Georg Schölly


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

like image 38
bobince Avatar answered Oct 21 '22 08:10

bobince