Redirect to another webpage using JavaScript

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

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.

0
JavaScript 3 years 0 Answer 432 views 0

About w3r

Leave an answer

Browse

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>