Open In App

JavaScript BOM Location object

The Browser Object Model(BOM) provides the properties and methods for JavaScript to interact with the browser. BOM allows performing actions to manipulate the browser window through BOM objects without affecting the contents of the page i.e. the document. BOM objects are global objects. The BOM objects used to manipulate the browser window that is:

These objects are children of the window object. The window object represents the browser window. So, they can be used either with the prefix: window.object_name or without using the prefix object_name



Syntax:

console.log("URL of the web page " + location.href)

Syntax:



console.log("Domain name of current host page is " + location.hostname)

Syntax:

console.log("Protocol used by the current page is " + location.protocol)

Syntax:

location.assign("http://www.google.com")

Syntax:

location.reload();

Example: This example uses location.href property of the location object. 




<!DOCTYPE html>
<html>
<body>
    <p id="a"></p>
   
    <script>
        document.getElementById("a").innerHTML
            = " URL of the currently loaded page is "
            + location.href;
    </script>
</body>
</html>

Output:

 

Article Tags :