Sometimes as a developer we need to know the address (URL) of the current page in order to generate some page links using javaScript, in oder to get the address of the current page we can make use of window.location object,
File : getAddress.html<html>
<head>
<title>Get current page address using JavaScript</title>
</head>
<body>
<div id="pageDetails"></div>
<input type="button" value="Click to get Address" onclick="getCurrentPageAddress()">
<script>
function getCurrentPageAddress() {
var currPageURL = window.location;
document.getElementById("pageDetails").innerHTML = "Current Page Address : " + currPageURL;
}
</script>
</body>
</html>

Get Page Address using JavaScript
We have a webpage with a button when clicked the address of the current page is displayed within the div element with id pageDetails.
Note: window.location object is also used to redirect a page to another.
More Posts related to JavaScript,
- Add Animated Scrolling to Html Page Title Script
- How to get query string in JavaScript HTML location.search
- How to get current URL Location using Javascript HTML
- How to detect Browser and Operating System Name and Version using JavaScript
- Submit html form on dropdown menu value selection or change using javascript
- How to Print from JavaScript HTML using window.print
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- JavaScript : Get current page address
- How to send email from JavaScript HTML using mailto
- Send Extra Data with Ajax Get or Post Request
- Write javaScript code in Swedish using FikaScript
- Get Device Screen Width and Height using javaScript
- How to get UTC (GMT) using javascript
- Javascript convert text case from uppercase to lowercase
- Loading previous page using html button using JavaScript
- [javaScript] Convert text case to lowercase
- Detect if Cookies are enabled using JavaScript
More Posts:
- Unable to load VM from snapshot. The snapshot has been saved for a different hardware configuration - Android
- Get Wifi Details : Android Programming - Android
- JSON Syntax : JSON Tutorial - Json-Tutorial
- Word count in Notepad++ - NotepadPlusPlus
- SharePoint Server 2016 error - Failed to connect to the configuration database - SharePoint
- Android Alert Dialog with Checkboxes example - Android
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager - Android
- [Notepad++] Remove CR Carriage Return and LF Line feed (CRLF) - NotepadPlusPlus
- Failed to install Android.apk on device 'emulator-5554': timeout - Android-Studio
- How to get Mobile Screen Resolution Width and Height programatically - Android
- Tomcat Manager Default Username and Password - Tomcat
- Turning Off Chat in Gmail - Google
- [Solved] SharePoint Illegal operation attempted on a registry key that has been marked for deletion - SharePoint
- Find Sum of two numbers - C-Program
- Struts 2 Hello World Example in Eclipse - Java