HTML - DOM Document documentURI Property



The documentURI property is used to set or return the document's location. This property can be used on various document types other than HTML.

Syntax

Set the URI location
document.documentURI = locationURI;
Get the URI location
document.documentURI;

Return Value

This property returns a string value representing URL of the document. It returns null if the document was created within memory.

Examples of HTML DOM Document 'documentURI' Property

The following examples illustrates to get and set the URI location.

Get the URI location

The following example gives the URL location of the current HTML document.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM documentURI Property
    </title>
</head>
<body>
    <button onclick="fun()">Click me</button>
    <p id="uri"></p>
    <script>
        function fun() {
            let x = document.documentURI;
            document.getElementById("uri").innerHTML = "URL: " + x;
        }
    </script>
</body>
</html>

Set the URI location

Here is an example to set the URI location of your document.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM documentURI Property
    </title>
</head>
<body>
    <button onclick="fun()">Click me</button>
    <p id="uri"></p>
    <script>
        function fun() {
            let x = document.documentURI = "https://www.tutorialspoint.com/";
            document.getElementById("uri").innerHTML = "URL: " + x;
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
documentURI Yes 1 Yes 17 Yes 1 Yes 3 Yes 12.1
html_dom.htm
Advertisements