Navigate to the new URL and makes an entry in the browser's history stack in JavaScript

Description

The following code shows how to navigate to the new URL and makes an entry in the browser's history stack.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
location.href = "http://www.java2s.com";
</script><!--from   ww  w .j a  va2  s. c o m-->
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Navigate to the new URL and makes an entry in the browser
Home »
  Javascript Tutorial »
    Browser »
      Browser Location
Javascript Tutorial Browser Location
Add search query to a URL in JavaScript
Change the hostname of location in JavaScri...
Change the path name property in Location o...
Change the port for location object in Java...
Force a reload from the server in JavaScrip...
Navigate to a URL without adding an entry i...
Navigate to the new URL and makes an entry ...
Reload the current page in JavaScript