Redirecting the Browser


location.href = "newPage.html"; 

The location.href property allows read and write access to the URL of the current page. Consequence: Setting location.href to another value redirects the browser, which then loads the new page, as the preceding code shows.

Tip

This can also be done by HTML means:

<meta http-equiv="Refresh" content="X; URL=Y" /> 


The placeholder X stands for the number of seconds to wait until the new page is loaded; Y denotes the new URL.


The previous page then lands in the history of the browser. If you however want to replace the old page in the browser history (to make the back button not work as expected here), use the location.replace() method:

location.replace("newPage.html"); 





JavaScript Phrasebook(c) Essential Code and Commands
JavaScript Phrasebook
ISBN: 0672328801
EAN: 2147483647
Year: 2006
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net