javascript redirect function 1

javascript redirect function

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";

Here is what the above code is Doing:
1. window.location.assign() loads a new document.
2. window.location.replace() replaces the current document with a new one.
3. window.location.reload() reloads the current document.
4. window.location.href returns the href (URL) of the current page.
5. window.location.hostname returns the domain name of the web host.
6. window.location.pathname returns the path and filename of the current page.
7. window.location.protocol returns the web protocol used (http: or https:).
8. window.location.origin returns the protocol, hostname and port number of a URL.
9. window.location.search returns the URL parameters.
10. window.location.hash returns the anchor part of a URL.

Similar Posts