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:


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:


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

window.location = "";

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