How to use Location Object in JavaScript
In this article I am going to explain about Location object in JavaScript.
JavaScript Location Object
JavaScript Location object is an parts of window object and its contain information about current visit Url. Information Such as Host name, port number, path name etc.
Syntax
Example // This example will display host name of current url
<html>
<head>
<script type="text/javascript">
function myfun() {
document.write(location.hostname);
}
</script>
</head>
<body>
<button onclick="myfun()">
click me</button>
</body>
</html>
|
Output
Example //This example will return port number of current Url
<html>
<head>
<script type="text/javascript">
function myfun() {
document.write("Port No :-" + location.port);
}
</script>
</head>
<body>
<button onclick="myfun()">
click me</button>
</body>
</html>
|
Output
You may also want to read these related articles: here
Ask Your Question
Got a programming related question? You may want to post your question here