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"); |