title | slug | date | categories | tags | ||
---|---|---|---|---|---|---|
how to redirect a URL in JavaScript |
/howto-redirect-url-javascript |
2014-07-07 09:02:44 +0500 |
|
|
Here's how you redirect a URL in JavaScript. Just set the value of window.location.replace
to the URL you want.
<script type="text/javascript"> window.location.href = "http://www.url.com" </script>
When redirecting, window.location.replace
is preferred over window.location.href
.
// similar behavior as an HTTP redirect window.location.replace("http://stackoverflow.com");// similar behavior as clicking on a link window.location.href = "http://stackoverflow.com";