Redirect via JavaScript

Sometimes you need to redirect to a page from client side JavaScript. You can do this in two ways:

  • Go to a specific page with a “link pressed” like behavior. That means that your current page will be put into the browser’s back stack:
    window.location.href = "www.redirect-url.com";
    
  • Do not add the current page to the back stack. This is very similar with a server side redirect:
     window.location.replace("www.redirect-url.com");
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s