Technical Training
JavaScript TutorialTable of Contents
JavaScript Location Object Properties
Properties: hostname, href and pathname
Properties : port, protocol and searchProperties : port, protocol and search
JavaScript Location Object Properties
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:
|
for example
</script>
<html>
<body>
<script type="text/javascript">
document.write(location.port);
</body>
</html>
Then the output of the above program is
|
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:
|
for example
</script>
<html>
<body>
<script type="text/javascript">
document.write(location.protocol);
</body>
</html>
Suppose the current URL is: http://xforsys.com/example.htm#test5
Then the output of the above program is
|
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:
|
In the above, the path is taken from question mark(?) of the current URL.
for example
</script>
<html>
<body>
<script type="text/javascript">
document.write(location.search);
</body>
</html>
Suppose the current URL is: http://xforsys.com/example.asp?filename=test10
Then the output of the above program is
|
The location.search in document.write takes the symbol starting from ? in the current URL and displays it giving the output as ?filename=test10
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







