Exforsys.com
 
Home Tutorials JavaScript
 

JavaScript Location Object Properties

 

Properties : port, protocol and search

Page 3 of 3


port:

The hostname property for returning the hostname alone of the current URL is similar to the port property. The port property of location object is used for setting or returning the port number of the current URL. This port number refers to the communications port used by the server.



General syntax of port property of location Object:



location.port=portnumber



for example



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


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



Then the output of the above program is



24



The number 24 displayed above specifies the port number of the current URL.


protocol:

As the name of this property suggests, the protocol property of location object is used for setting or returning the protocol of the current URL.


General syntax of protocol property of location Object:



location.protocol=path



for example



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


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



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


Then the output of the above program is



http:



The location.protocol in document.write takes the protocol specified in the current URL which is http: and displays it as shown above.


search:

The search property of the location object is a string and it is used to set and return the value from the current URL starting from question mark(?)


General syntax of search property of location Object:



location.search=path



In the above, the path is taken from question mark(?) of the current URL.


for example



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


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



Suppose the current URL is: http://xforsys.com/example.asp?filename=test10



Then the output of the above program is



?filename=test10



The location.search in document.write takes the symbol starting from ? in the current URL and displays it giving the output as ?filename=test10




First Page: JavaScript Location Object Properties


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 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape