Base href attribute

Definition and usage

href Sets or returns the value of the href attribute in the base element.

Base href attribute Specify the base URL for all relative URLs on the page.

By default, the base URL is the location of the current document, but it can be overridden by this attribute.

See also:

HTML-Referenzhandbuch:HTML <base>-Tag

Example

Example 1

Return the base URL for all relative URLs on the page:

var x = document.getElementById("myBase").href;

Try it yourself

Example 2

Change the value of the base URL:

document.getElementById("myBase").href = "https://www.codew3c.com/html/";

Try it yourself

Syntax

Return href attribute:

baseObject.href

Set href attribute:

baseObject.href = URL

Attributwert

Wert Beschreibung
URL Legt die Basis-URL fest.

Technische Details

Rückgabewert: Zeichenfolgenwert, der die Basis-URL aller relativen URLs auf der Seite angibt, einschließlich des Protokolls (z.B. http://).

Browser-Unterstützung

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Unterstützung Unterstützung Unterstützung Unterstützung Unterstützung

Verwandte Seiten

HTML-Referenzhandbuch:HTML <base> href-Attribut