how to redirect a URL in JavaScript
July 7, 2014
Here's how you redirect a URL in JavaScript. Just set the value of window.location.replace to the URL you want.
code
<script type="text/javascript">
window.location.href = "http://www.url.com"
</script></pre>
When redirecting, `window.location.replace` is preferred over `window.location.href`.
```js
// 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";</pre>
## Links
- [StackOverflow: How do I redirect to another page in JavaScript/jQuery?](http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript)
- [how to do a time delay redirect in JavaScript](http://www.tizag.com/javascriptT/javascriptredirect.php)