Javascript Location Object
The location object in JavaScript helps in storing the information of current URL of the window object. It is a child object of the window object.
Location object Properties & Methods :
Property Description Example
location.href Represents a string specifying the entire URL
location.hostname Represents the server name, subdomain, and domain name of a URL
location.pathname Returns the path and filename of the current page java-applications.php
location.protocol returns the web protocol used http: or https:
location.assign Loads a new document in the browser  
location.reload Reloads the current document that is contained in the location.href property  
location.replace replaces the current document with the specified new one, you can not navigate back to the previous document using the browser's Back button  
Example Program :
<title>JavaScript Location Object</title>
<script type="text/javascript">
function gotoLoc()
    window.location.href = window.document.loctn.Protocol.
    text + document.loctn.Hostname.value + document.loctn.
<h3>Enter URL in following sections</h3>
<form name="loctn" method="post">
<select name="Protocol" size="1">
Host Name:
<input type="text" size="20" maxlength="256" name="Hostname" value="">
Path Name:
<input type="text" size="20" maxlength="100" name="Pathname" value="/">
<input type="button" name="Go" value="Go" onClick="gotoLoc()">
Output :