24 lines
		
	
	
		
			916 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
		
		
			
		
	
	
			24 lines
		
	
	
		
			916 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
|   | --- | ||
|  | title: Window Location | ||
|  | --- | ||
|  | ## Window Location
 | ||
|  | 
 | ||
|  | The `window.location` object can be used to get information on 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, as just `location`. | ||
|  | 
 | ||
|  | #### 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.host` returns both the host name and any associated port | ||
|  | - `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 | ||
|  | 
 | ||
|  | #### More Information:
 | ||
|  | 
 | ||
|  | <a href='https://www.w3schools.com/js/js_window_location.asp' target='_blank' rel='nofollow'>W3C</a> | ||
|  | 
 | ||
|  | [MDN](https://developer.mozilla.org/docs/Web/API/Window/location) |