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,
- npm WARN saveError ENOENT: no such file or directory, open /mnt/c/package.json
- How to send email from JavaScript HTML using mailto
- Write javaScript code in Swedish using FikaScript
- [javaScript] Convert text case to lowercase
- Detect if Cookies are enabled using JavaScript
- How to get query string in JavaScript HTML location.search
- Remove items from JavaScript array
- JavaScript date in yyyy-MM-dd format
- Send Extra Data with Ajax Get or Post Request
- Get Device Screen Width and Height using javaScript
More Posts:
- ADT quit unexpectedly error on Mac OSX Android Eclipse SDK - Android
- Building library Gradle Project Info: Downloading services.gradle.org - Android-Studio
- Turn Off Google Analytics intelligence Alert Emails - Google
- MySQL Error :1006 SQLSTATE: HY000 (ER_CANT_CREATE_DB) Message: Can't create database 'mydb' (errno: 28) - MySQL
- Replace tabs by spaces or comma Notepad++ - NotepadPlusPlus
- PowerShell iterate and get all SharePoint sites and sub sites - SharePoint
- Turn on off volume change button sounds Mac OS X - Mac-OS-X
- Android Lint app_name is not translated in af (Afrikaans) am (Amharic) ar (Arabic) bg (Bulgarian) - Android
- How to Detect Phone Shakes Android Programming - Android
- MySQL : Error :1000 SQLSTATE: HY000 (ER_HASHCHK) Message: hashchk Server Error - MySQL
- How to add border to Android Button - Android
- How to Center Align Image in Bootstrap - CSS
- Recover SharePoint if the SQL Server IP changes - SharePoint
- Google Chrome Update failed (error: 12) - Chrome
- Send Email using SharePoint PowerShell command - SharePoint