Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 1.05 KB

redirect-url-javascript.md

File metadata and controls

25 lines (22 loc) · 1.05 KB
title slug date categories tags
how to redirect a URL in JavaScript
/howto-redirect-url-javascript
2014-07-07 09:02:44 +0500
JavaScript
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";

Links