Reputation: 498
I always saw in the developer tool that both the entities(baseURI and URL) show the same URL, which is shown in the address bar most of the time. These are the properties of window.document
object. So when is the situation that base URI property is "undefined"?
Upvotes: 0
Views: 1562
Reputation: 3218
Adding to the answer of @Thomas. The IE11 (or lower) does not support baseURI
property thus it will always be undefined.
Upvotes: 1
Reputation: 182000
They do different things.
For what's in the address bar, you typically want window.location.href
.
The baseURI
property of nodes, on the other hand, is used as the base for resolving relative URLs within that node, for example the src
of an image or href
of a link. The baseURI
can be changed by adding a <base>
element.
I have found no situations where baseURI
is undefined
. Even in a document created through document.implementation.createDocument
, it is just inherited from the current document
. Adding an empty <base>
element has no effect. Assigning undefined
to baseURI
is simply ignored.
Upvotes: 3