Open In App

HTML DOM URL Property

Last Updated : 05 Jul, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The DOM URL property in HTML is used to return a string that contains the complete URL of the current document. The string also includes the HTTP protocol such as ( http://).

Syntax:

document.URL

Return Value: It returns a string value that represents the full URL of the document. 

Example: In this example, we simply display the GeeksforGeeks URL using DOM URL Property.

HTML




<!DOCTYPE html>
<html>
 
<body>
    <h2>GeeksforGeeks</h2>
    <p id="GfG">GeeksforGeeks URL:
        <br/>
        <span id="GfG">
            https://www.geeksforgeeks.org/
        </span>
    </p>
    <script>
        document.getElementById(
            "https://www.geeksforgeeks.org/")
            .textContent = document.URL;
    </script>
</body>
 
</html>


Output:

document.URL() Property

Example: This example illustrates the document.URL property in HTML to get the URL of the current site.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>DOM document.URL() Property</title>
    <style>
        h1 {
            color: green;
        }
         
        h2 {
            font-family: Impact;
        }
         
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h2>DOM document.URL() Property</h2>
 
    <p>
        For displaying the URL of the document,
        double click the "View URL" button:
    </p>
 
    <button ondblclick="myURL()">View URL</button>
    <p id="url"></p>
 
    <script>
        function myURL() {
            var gfg = document.URL;
            document.getElementById("url").innerHTML = gfg;
        }
    </script>
</body>
 
</html>


Output:

Displaying the current URL using the document.URL() Property

Supported Browsers:

  • Google Chrome 1
  • Internet Explorer 4
  • Microsoft Edge 12
  • Firefox 1
  • Opera 3
  • Safari 1


Previous Article
Next Article

Similar Reads

What is URL Locator & what are common schemes used for the URL in HTML ?
Every HTML document on the internet has a unique URL. URL stands for Uniform Resource Locator. The URL is the HTML document's address on the internet. Any file that can be accessed via the internet has a URL, including images, JavaScript files, CSS files, Flash files, and so on. To view an HTML document in a browser, enter the URL of the document i
3 min read
HTML | DOM Input URL size Property
The DOM Input URL size Property in HTML DOM is used to set or return the value of the size attribute of an Input url Field. The size attribute is used to define the width of a url field. Its default value is 20. Syntax: It returns the Input url size property.urlObject.sizeIt is used to set the Input url size property.urlObject.size = number Propert
2 min read
HTML | DOM Input URL placeholder Property
The DOM Input URL placeholder Property is used to set or return the value of the Placeholder attribute of a URL Field.The placeholder attribute specifies a short hint as a text in the input field that describes the expected value. Syntax: It is used to return the placeholder property. urlObject.placeholder It is used to set the placeholder property
2 min read
HTML | DOM Input URL value Property
The DOM Input URL value Property in HTML DOM is used to set or return the value of the input URL field. The attribute specifies the default value or the user type value. Syntax: It returns the value property.urlObject.valueIt is used to set the value property.urlObject.value = url Property Values: It contains a value i.e URL which specifies the abs
2 min read
HTML | DOM Input URL type Property
The DOM Input URL type Property in HTML DOM is used for returning the Which type of form element the URL field is. This Property will always return "URL".Syntax: urlObject.type Return Value: It returns a string value which represent the type of form element the URL field is. Example: This Example illustrates how to return the type Property. C/C++ C
1 min read
HTML | DOM Input URL required Property
The DOM Input URL required Property in HTML DOM is used to set or return whether Input url Field should be filled or not when submitting the form. This property is used to reflect the HTML required attribute.Syntax: It returns the Input url required property. urlObject.requiredIt is used to set the Input url required property. urlObject.required =
2 min read
HTML | DOM Input URL name Property
The DOM Input URL name Property in HTML DOM is used to set or return the value of name attribute of a URL field. The name attribute is required for each input field. If the name attribute is not specified in an input field then the data of that field would not be sent at all. Syntax: It returns the Input url name property.urlObject.nameIt is used t
2 min read
HTML | DOM Input URL readOnly Property
The DOM Input URL readOnly Property is used to set or return whether a URL Field should be read-only or not. It means that a user can not modify or changes the content already present in a particular Element (However, a user can tab to it, highlight it, and copy the text from it) whereas a JavaScript can be used to change the read-only value and ma
2 min read
HTML | DOM Input URL pattern Property
The DOM Input URL pattern Property in HTML DOM is used to set or return the pattern attribute of a URL field. It is used to specify the regular expression on which the input elements value is checked. Use the global title attribute to describe the pattern for helping the user. Syntax: It returns the Input url pattern property.urlObject.patternIt is
2 min read
HTML | DOM Input URL maxLength Property
The DOM Input URL maxLength Property in HTML DOM is used to set or return the value of maxlength attribute of a URL Input Field. It specifies the maximum number of characters that have been allowed in the URL field. The default value of Input URL maxLength property is 524288. Syntax: It returns the Input url maxLength property. urlObject.maxLength
2 min read
Article Tags :