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,
- Get Current time in GMT/UTC using JavaScript
- How to get current URL Location using Javascript HTML
- Excel Fix: SECURITY RISK Microsoft has blocked macros from running because the source of this file is untrusted.
- Convert Javascript object to JSON String example
- Fix: ReferenceError: require is not defined in ES module scope [Node]
- [JavaScript] Remove all Newlines From String
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- Fix: Error: error:0308010C:digital envelope routines::unsupported NodeJs/Vue/React
- Pure JavaScript Digital Clock Widget to get GMT/UTC Time Now
- Fix: npm vs code eacces permission denied unlink /usr/local/bin/code
- Power of Print Statements in JavaScript: A Comprehensive Guide
- [javaScript] Convert text case to lowercase
- JavaScript: Count Words in a String
- JavaScript date in yyyy-MM-dd format
- How to send email from JavaScript HTML using mailto
- How to get UTC (GMT) time using JavaScript
- JavaScript: Generate Random Numbers between 1 and 3
- How to get query string in JavaScript HTML location.search
- Fix: Uncaught ReferenceError: exit is not defined - Node.js REPL
- Detect if Cookies are enabled using JavaScript
- Submit html form on dropdown menu value selection or change using javascript
- Send Extra Data with Ajax Get or Post Request
- Loading previous page using html button using JavaScript
- 10 ways to Convert String to a Number in JavaScript
- JavaScript: Check if variable is a number
More Posts:
- Change CKEditor Table Properties default width - CKEditor
- Iterate over an Array using Java 8 Stream and foreach - Java
- How to take a screenshot of android emulator (AVD) screen - Android
- Python: Replace the First Occurrence of String in a String - Python
- How to Change Mac Computer and Localhost Name using Terminal - MacOS
- How to Save Jupyter Notebook as PDF - Python
- How to Turn off "Terminal" would like to access files message on Mac? - MacOS
- Capitalize the first letter of each word using Notepad++ - NotepadPlusPlus