Exforsys.com
 
Home Tutorials JavaScript
 

JavaScript Location Object Properties

 

JavaScript Location Object Properties

Page 1 of 3

JavaScript Location Object Properties

In this JavaScript Tutorial you will learn about Properties of Location Object - hash, host, hostname, href, pathname, port, protocol and search property



The Location object contains information about the current URL. This representation is a string that denotes the different portions of the URL as below:



<protocol>//<host>[:<port>]/<pathname>[<hash>][<search>]



The location object has a number of properties and methods in it. The usage, syntax and explanation with examples of each of the properties and methods of the Location object are explained in this section and the following sections.


Properties of Location Object:

hash:

The hash property of location object starts with the symbol hash denoted as #, specifying an anchor name in an URL. The hash property is also used for returning the URL.


General syntax of hash property of location Object:



location.hash = anchorname



for example



<
html>
   <
body>
      <script type="text/javascript">
          
document.write(location.hash);     


      </script>
   </body>
</
html>



Suppose the current URL is: http://xforsys.com/example.htm#test5


Then the output of the above program is



#test5



The location.hash in document.write takes the symbol starting from hash in the current URL and displays it giving the output as #test5


host:

The property of location objects are used for setting or returning the hostname and port number of the current URL.


General syntax of host property of location Object:



location.host



for example


The location.host in document.write takes the hostname in the current URL and displays it with the output exforsys.com



<
html>
   <
body>
      <script type="text/javascript">
          
document.write(location.host);     


      </script>
   </body>
</
html>



Suppose the current URL is: http://xforsys.com/example.htm#test5



Then the output of the above program is



xforsys.com



The location.host in document.write takes the hostname in the current URL and displays it with the output exforsys.com


Next Page: Properties: hostname, href and pathname


Read Next: JavaScript Location Object



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape