Redirect to another webpage using JavaScript
ReportPlease briefly explain why you feel this question should be reported .
window.location.replace
Similar to window.location.assign, except that it “replaces” the current document, removing the previous one from the back button history.
Syntax:
var = window.location.replace(url);
Parameters
url – Data-type: String
Return Value:
Returns an object of type
Examples:
Force a new page to load and replace the current one.
// similar behavior as an HTTP redirect window.location.replace("https://w3resource.com"); // similar behavior as clicking on a link window.location.href = "https://w3resource.com";
Note:
Use window.location.assign because it retains the back button history. The replace method removes the current page from the back history, and therefore may confuse the user.
Leave an answer