➥ JS Tutorial
- JS HOME
- JS introduction
- JS Where to
- JS Output
- JS Statements
- JS Syntax
- JS Variables
- JS Operators
- JS Assignment
- JS Data Types
- JS Functions
- JS Objects
- JS Events
- JS Sting methods
- JS String Search
- JS Arrays Methods
- JS Arrays
- JS Sorting Arrays
- JS Array Iteration
- JS Math Object
- JS Comparison & Logical Operators
- JS if else and else if
- JS Switch Statement
- JS For Loop
- JS For In
- JS For Of
- JS While Loop
- JavaScript Break
- JS Sets
- JavaScript typeof
- JS Type Conversion
- JS Bitwise Operations
- JS JSON
- JS Best Practices
- JS Reserved Words
- JS Number Methods
➥ JS Objects
➥ JS Functions
➥ JS Classes
➥ JS HTML DOM
- JavaScript HTML DOM
- JS HTML DOM Document
- JS HTML DOM Elements
- Changing HTML
- JS Forms
- JS HTML DOM - CSS
- DOM Events
- HTML DOM Event Listener
➥ JS Browser BOM
➥ JS Web APIs
➥ JS AJAX
➥ JS JSON
Tutorial
JavaScript Window Location
The window.location
object can be used to get the current page address (URL) and to redirect the browser to a new page.
The window.location
object can be written without the window prefix.
Some examples:
• window.location.href returns the href (URL) of the current page
• window.location.hostname returns the domain name of the web host
• window.location.pathname returns the path and filename of the current page
• window.location.protocol returns the web protocol used (http: or https:)
• window.location.assign() loads a new document
Window Location Href
The window.location.href
property returns the URL of the current page.
Example:
Display the href (URL) of the current page:
EXAMPLE ❯
Window Location Hostname
The window.location.hostname
property returns the name of the internet host (of the current page).
EXAMPLE ❯
Window Location Pathname
The window.location.pathname
property returns the pathname of the current page.
EXAMPLE ❯
Window Location Protocol
The window.location.protocol
property returns the web protocol of the page.
EXAMPLE ❯
Window Location Port
The window.location.port
property returns the number of the internet host port (of the current page).
Example:
Following example Display the name of host
EXAMPLE ❯
Window Location Assign
The window.location.assign()
method loads a new document.