<BASE> | NN all IE all HTML all | |
<BASE> | HTML End Tag: Forbidden | |
A base element is defined inside a document's head element to instruct the browser about the URL path to the current document. This path is used as the basis for all relative URLs used to specify various src and href attributes in the document. The base element's URL should be a complete URL, including the document name (though browsers tend to support URLs to directories, too). The browser calculates the base URL path to the directory holding the document. If you specify <BASE href="http://www.megacorp.com/products/index.html">, the href attribute of a link on that page to widgets/framitz801.html resolves to the full URL of http://www.megacorp.com/products/widgets/framitz801.html. Similarly, a relative URL can walk up the hierarchy with the dot syntax. For example, from the base element defined earlier, an img element in the index.html page might be set for src="../images/logo.jpg". That reference resolves to http://www.megacorp.com/images/logo.jpg. By and large, today's browsers automatically calculate the base URL of the currently loaded document, thus allowing use of relative URLs without specifying a base element. This is especially helpful when you are developing pages locally and don't want to change the base element settings when you deploy the pages. The HTML 4 specification states that a document lacking a base element should by default use the current document's URL as the base URL. Of course, this is only for true web pages, rather than HTML-enhanced documents such as email messages, which have no default base URL. You can also use the base element to define a default target for any link-type element in the document. Therefore, if all links are supposed to load documents into another frame, you can specify this target frame once in the base tag and not worry about target attributes elsewhere in the document. If you wish to override the default for a single link, you may do so by specifying the target attribute for that element (but see the note in the target attribute). The only attribute this element has in common with other elements is the id attribute. |
||
Example | ||
<HEAD> <BASE href="http://www.megacorp.com/index.html" target="_top"> </HEAD> |
||
Object Model Reference | ||
[window.]document.getElementById(elementID)
|
||
Element-Specific Attributes | ||
|
||
Element-Specific Event Handler Attributes | ||
None. |
href | NN all IE all HTML all |
href="URL" | Optional |
The href attribute is a URL of a document whose server path is to be used as the base URL for all relative references in the document. This is typically the URL of the current document, but it can be set to another path if it makes sense to your document organization and directory structure. |
|
Example | |
<BASE href="http://www.megacorp.com/products/index.html"> |
|
Value | |
This should be a full and absolute URL to a document. |
|
Default | |
Current document pathname. |
|
Object Model Reference | |
[window.]document.getElementsByTagName("base")[0].href
[window.]document.getElementById(elementID).href
|
target | NN all IE all HTML 4 |
target="windowOrFrameName" | Optional |
If all or most links and area maps on a page load documents into a separate window or frame, you can set the target attribute of the base element to take care of targeting for all of those elements. You can set the target attribute without setting the href attribute if you want to set only the base target reference. Strict DTDs for HTML 4 and XHTML do not support the target attribute of any element because frames and windows are outside the scope of pure document markup. In fact, framesetting documents will not validate in the strict environmentthus the purpose of the separate frameset DTDs for HTML 4 and XHTML. If your documents must validate with these strict DTDs, and you wish to support targets, use scripts to set target properties of links, image maps, and forms after the page has loaded. |
|
Example | |
<BASE target="rightFrame"> |
|
Value | |
Case-sensitive identifier when the frame or window name has been assigned via the target element's name attribute. Four reserved target names act as constants: |
|
Default | |
_self |
|
Object Model Reference | |
[window.]document.getElementsByTagName("base")[0].target
[window.]document.getElementById(elementID).target
|