How to redirect the user with javascript


Problem

I want to redirect the user to another site/page with javascript.



Solution

It really depends if you want to redirect or to send the user to another location.

a redirect is achieved with

window.location.replace("http://mynewlocation.com");

and a simulated click with

window.location.href = "http://mynewlocation.com";

replace() doesn't keep the originating page in the session history, so you don't create one of those back button bags of pain.

Comments




Please sign-in to post a comment