You are here: Reference > JavaScript > client-side > HTML DOM > properties > href (base)

href property (base)

Browser support:
Sets or retrieves the base URL to be used throughout the document for relative URL addresses.
By default, the base URL is the location of the current document, but it can be overridden by this property.

Syntax:

object.href;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: href

Possible values:

String that sets or retrieves the URL to use as a base URL.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the href attribute:
<head>
    <base href="http://help.dottoro.com/external/examples/" />
</head>
<body>
    This link is relative to the <a href="common/images/area.gif">base URL</a>.
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the href property:
<head>
    <base id="myBase" href="http://help.dottoro.com/external/examples/" />
    <script type="text/javascript">
        function GetBaseHref () {
            var base = document.getElementById ("myBase");
            alert (base.href);
        }
    </script>
</head>
<body>
    This link is relative to the <a href="common/images/area.gif">base URL</a>.
    <button onclick="GetBaseHref ();">Get base href!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content