The BOM objects used to manipulate the browser window that are:
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
- location.href returns the URL of the web page currently loaded in the browser window.
console.log("URL of the web page " + location.href)
- location.hostname returns the domain name of the current host (excluding the port number).
console.log("Domain name of current host page is " + location.hostname)
- location.protocol returns the web protocol being used by the current web page (http:, file: or https:)
console.log("Protocol used by the current page is " + location.protocol)
- location.assign returns a new web page loaded in the window, when the complete address is specified.
- location.reload reloads the current page. Its function is the same as that of reload button in the browser window.
Example: This example uses location.href property of the location object.