Redirect to Another Webpage With JavaScript

JavaScriptPosted on

Using the replace() and assign() JavaScript functions we can redirect to another URLs.

With the replace() function, we create a redirect where the previous page will be replaced, thus inaccessible through the browser’s back button:

window.location.replace("https://pineco.de");

With the assign() funlction, we can trigger a mouse click like navigation so it will redirect us to the new page, but we can still navigate back:

window.location.assign("https://pineco.de");

There is a third method which is the window’s read-only location object, where we can pass any string (valid URL):

window.location = "https://pineco.de";

Need a web developer? Maybe we can help, get in touch!

Looking for web dev job?
You can check them on Jooble.

To see and write comments, you must allow the related (Disqus) cookies. For more information, please visit our privacy policy page.

Similar Posts

More content in JavaScript category