Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
JavaScript Program To Get The Current URL
In this example, you will learn to write a JavaScript program that will get the current URL.
Example: Get The Current URL
// program to get the URL
const url1 = window.location.href;
const url2 = document.URL;
console.log(url1);
console.log(url2);
Output
https://www.google.com/ https://www.google.com/
In the above program, window.location.href property and document.URL property are used to get the URL of the current page.
Both the window.location.href and the document.URL properties return the URL of the current page.
Did you find this article helpful?