Definition and Usage 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.
Window Location
The window.location object can be written without the window prefix.
Some examples:
The window.location.href property returns the URL of the current page.
Window Location Hostname
The window.location.hostname property returns the name of the internet host (of the current page).
Window Location Pathname
The window.location.pathname property returns the pathname of the current page.
Window Location Protocol
The window.location.protocol property returns the web protocol of the page.
Window Location Port
The window.location.port property returns the number of the internet host port (of the current page).
Window Location Assign
The window.location.assign() method loads a new document.
Differents way how to declare Window Location in program.
CODING:The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.
Window Location
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
The window.location.href property returns the URL of the current page.
Window Location Hostname
The window.location.hostname property returns the name of the internet host (of the current page).
Window Location Pathname
The window.location.pathname property returns the pathname of the current page.
Window Location Protocol
The window.location.protocol property returns the web protocol of the page.
Window Location Port
The window.location.port property returns the number of the internet host port (of the current page).
Window Location Assign
The window.location.assign() method loads a new document.
Differents way how to declare Window Location in program.
<!DOCTYPE html>
<html>
<body>
<div id="div"></div>
<p><b>Note: </b>If the port number is default (80 for http and 443 for https), most browsers will display 0 or nothing.</p>
<button onclick="newWin()">Load new document</button>
<script>
var text="<b>The full URL of this page is:</b>" + window.location.href;
text += "<br><b>Page hostname is </b>" + window.location.hostname;
text += "<br><b>Page path is </b>" + window.location.pathname;
text += "<br><b>Page protocol is </b>" + window.location.protocol;
text += "<br><b>Port number is </b>" + window.location.port;
document.getElementById("div").innerHTML=text;
function newWin() {
window.location.assign("https://cprogramaboutexample.blogspot.com");
}
</script>
</body>
</html>
<html>
<body>
<div id="div"></div>
<p><b>Note: </b>If the port number is default (80 for http and 443 for https), most browsers will display 0 or nothing.</p>
<button onclick="newWin()">Load new document</button>
<script>
var text="<b>The full URL of this page is:</b>" + window.location.href;
text += "<br><b>Page hostname is </b>" + window.location.hostname;
text += "<br><b>Page path is </b>" + window.location.pathname;
text += "<br><b>Page protocol is </b>" + window.location.protocol;
text += "<br><b>Port number is </b>" + window.location.port;
document.getElementById("div").innerHTML=text;
function newWin() {
window.location.assign("https://cprogramaboutexample.blogspot.com");
}
</script>
</body>
</html>
Thank you for this blog. It is very useful. Share more like this.
ReplyDeleteJava Online Course
Learn Java Online