Technical Training
JavaScript TutorialTable of Contents
JavaScript Location Object Properties
Properties: hostname, href and pathname
Properties : port, protocol and searchJavaScript Location Object Properties
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:
|
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:
|
for example
</script>
<html>
<body>
<script type="text/javascript">
document.write(location.hash);
</body>
</html>
Suppose the current URL is: http://xforsys.com/example.htm#test5
Then the output of the above program is
|
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:
|
for example
The location.host in document.write takes the hostname in the current URL and displays it with the output exforsys.com
</script>
<html>
<body>
<script type="text/javascript">
document.write(location.host);
</body>
</html>
Suppose the current URL is: http://xforsys.com/example.htm#test5
Then the output of the above program is
|
The location.host in document.write takes the hostname in the current URL and displays it with the output exforsys.com
JavaScript Tutorial
- JavaScript Browser Objects Part 2
- JavaScript Frame object
- JavaScript Form Object
- JavaScript FileUpload Object
- JavaScript Event Object Properties and Methods
- JavaScript Event Object
- JavaScript Elements and Embed Objects
- JavaScript Applet Objects
- JavaScript Browser Objects
- JavaScript Object Oriented Features
- JavaScript Window Object Open Method Part 2
- JavaScript Window Object Open Method
- JavaScript Window Object Timeout Methods
- JavaScript Location Object
- JavaScript Location Object Properties
- JavaScript History Object Properties and Methods
- JavaScript Document Object Methods Part II
- JavaScript Document Object Methods Part I
- JavaScript Document Object Properties
- JavaScript Document Object
- JavaScript Windows Object Properties Part II
- JavaScript Windows Object Properties Part I
- JavaScript DOM Window Object
- Working with JavaScript DOM Objects
- JavaScript Array Object Methods – Part II
- JavaScript Array Object
- JavaScript Array Object Methods – Part I
- JavaScript Boolean Object
- JavaScript OnError Event
- JavaScript Exception Handling – Part II
- JavaScript Exception Handling – Part I
- JavaScript Event Handler
- JavaScript Events Handling
- JavaScript Array Operations
- JavaScript Two Dimensional Arrays
- Passing values to JavaScript Function
- JavaScript Functions
- JavaScript Arrays
- JavaScript Iterative Structures - Part II
- JavaScript Iterative Structures - Part I
- JavaScript Math Object
- JavaScript Date Object
- JavaScript String Object
- JavaScript Objects
- JavaScript Confirm Box
- JavaScript Alert Box
- JavaScript Conditional Statements Part 2
- JavaScript Conditional Statements Part 1
- How to use JavaScript in HTML page
- JavaScript Variables
- JavaScript Features
- JavaScript Introduction







