The location property

The location property holds the current URL of the window.
This property is often use to redirect viewers to a new URL if the page has been moved.

<html>
<head>

<title>Page 1</title>

<script type="text/javascript" >
window.location = "page_2.html";
</script>

</head>

<body>

No JavaScript enabled?<br>
Click the link below for the new page.<br>
<a href="page_2.html">New Page</a>

</body>
</html>

The JavaScript in the head section sends the viewers to the page_2.html instantly.
In the body section there is a link to page_2.html for those who don’t have JavaScript enabled in their browsers.

Leave a Reply