Notes

how to redirect a URL in JavaScript

Edit on GitHub

JavaScript

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”;