Easy Tutorial
❮ Docker Tricks Zepto Js Source Analysis ❯

JavaScript Page Navigation and Redirection

Category Programming Technology

There are two methods to implement page redirection using JavaScript:

window.location.replace("url")

Similar to HTTP Redirection

Replace the address with a new URL. This method replaces the current item cached in history (on the client side) with the specified URL. Therefore, after using the replace method, you cannot access the replaced URL through "forward" and "back". This feature is very useful for creating transitional pages!

window.location.href="url"

Similar to clicking a link in an a tag.

Navigate to the specified URL.

Example

Examples

// Similar to HTTP redirection to tutorialpro.org
window.location.replace("https://www.tutorialpro.org");

// Similar to clicking a link to tutorialpro.org (an a tag)
window.location.href = "https://www.tutorialpro.org";

** Click here to share notes

Cancel

-

-

-

❮ Docker Tricks Zepto Js Source Analysis ❯