You are here: Reference > JavaScript > client-side > HTML DOM > properties > baseURI

baseURI property

Browser support:
10
Returns the base URL for the object.
Note: The baseURI property is supported in Opera from version 10.
Relative paths in the document are relative to the base URL. The base URL is the location of the current document by default, but it can be overridden by the base tag.

Syntax:

object.baseURI;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

String that represents the base URL.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the baseURI property:
<head>
    <base href="/external/examples/common/" />
    <script type="text/javascript">
        function GetBaseURL () {
            if ('baseURI' in document) {
                alert ("The base URL for the document:\n" + document.baseURI);
            }
            else {
                var baseTags = document.getElementsByTagName ("base");
                if (baseTags.length > 0) {
                    alert ("The base URL for the document:\n" + baseTags[0].href);
                }
                else {
                    alert ("The base URL for the document:\n" + window.location.href);
                }
            }
        }
    </script>
</head>
<body>
    <button onclick="GetBaseURL ()">Get the base URL for the document</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

User Contributed Comments

Post Content

Post Content