Skip to content
Related Articles

Related Articles

How to get the current URL using JavaScript ?
  • Last Updated : 14 Jul, 2020

The task is to get the Website URL. The current URL can be obtained by using the ‘URL’ property of the Document object which contains information about the current URL. The ‘URL’ property returns a string with the full location of the current page.




<!DOCTYPE html>
        h1 {
            color: green;
        h2 {
            font-family: Impact;
        body {
            text-align: center;
        JavaScript: Program to 
        get the website URL ?
        Click on Below Button 
        To Get Current URL
    <button onclick="GetURL()">
        Get URL
    <p id="url"></p>
        function GetURL() {
            var gfg = document.URL;
                "url").innerHTML = gfg;

Before clicking the button:

After clicking the button:

Supported Browser are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up
Recommended Articles
Page :