base

< html‎ | elements
Jump to: navigation, search

base



Summary

The base element (<base>) allows authors to specify the document base URL for the purposes of resolving relative URLs, and the name of the default browsing context for the purposes of following hyperlinks. The element does not represent any content beyond this information.


Overview Table

DOM Interface HTMLBaseElement

Examples

In the example below, the link to about_us.html is a link to http://www.example.com/news/about_us.html.

HTML

<html>
     <head>
          <title><base> element example</title>
          <base href="http://www.example.com/news/index.html">
     </head>
     <body>
          

Learn more <a href="about_us.html">about us</a>.

    </body>

</html>

This example sets the base URL of the document to a reference folder. Internet Explorer uses the base element to resolve the link to http://msdn.microsoft.com/workshop/author/dhtml

HTML

<html>
<head>
  <base href="http://msdn.microsoft.com/workshop/author/dhtml/reference/"/>
</head>
<body>
Click <a href="properties/href_2.asp">here</a> to learn about the 
href property.
</body>
</html>

This example retrieves the base URL from the document if a valid base element is specified in the document. Otherwise, the function returns null.

HTML

<script>
function GetBase()
{
    var oBaseColl = document.all.tags('BASE');
    return ( (oBaseColl && oBaseColl.length) ? oBaseColl[0].href : 
        null );
}
</script>

Notes

Remarks

When used, the base element must appear within the head of the document, before any elements that refer to an external source. If more than one base element occurs, only the first element will be recognized. Windows Internet Explorer 8 and later. When read, the value of the href attribute depends on the current document compatibility mode. In addition, relative URL's are no longer supported by the base element. Note Versions of Windows Internet Explorer prior to Windows Internet Explorer 7 would allow the base element to appear anywhere in the document tree, which caused relative paths to use the "nearest" base element as the base for the URL. Internet Explorer 7 strictly enforces the use of the base tag within the head of the document, and will ignore misplaced tags.

Standards information


Members

The base object has these types of members:

  • [#events Events]
  • [#methods Methods]
  • [#properties Properties]


Events

The base object has these events. {

Related specifications

Specification Status Related Changes
HTML 4.01 Specification W3C Recommendation
HTML5 W3C Working Draft

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic support ? ? ? ? ? ? ? ?

See also

Related articles

HTML












  • base













This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]