Home / Tips / Programming languages / Scripting languages / JavaScript / How to make a page redirect in JavaScript?

How to make a page redirect in JavaScript?

  • Currently 4 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 4/5 (1 votes cast)

Thank you for rating!

You have already rated this page, you can only rate it once!

Your rating has been changed, thanks for rating!

Log in or create a user account to rate this page.

The simplest way to make a redirect is by using window object (window.location.href):

window.location.href = 'http://mysite.com';

You also can use window.location.assign or window.location.replace:

window.location.assign( 'http://mysite.com' );

window.location.replace( 'http://mysite.com' );

While window.location.assign acts just like window.location.href, window.location.replace doesn't store original page in browser history.


Read also

Post comment


Quick navigation

General navigation