The document.baseURI
property in DOM returns the HTML document's base document.URL
.
Note: To read more on
document.URL
property, please refer to this Answer.
Now that we understand the primary use of the property, let us take a look at the syntax in the following code widget:
document.baseURI
The return value of this property is a string
that represents the base URI of the document and it is only for read-only purposes.
Let us take a look at a code example that makes use of this property:
<div>
tag, which encloses the content of the HTML page as seen in the output. The content of the HTML page can be further broken down into the following elements:<h3>
tag that displays the heading at the top of our HTML page.<p>
tag that we populate with the value of the base URI.<button>
for the user, which is listening for the onclick
event. It triggers the fetchbaseURI()
method.fetchbaseURI()
method to retrieve the base URI of the document. The method's body composes of the following lines of code:baseURI
variable.document.getElementById()
method to fetch the <p>
tag. Then, we use innerHTML
property to populate it with the value of baseURI
.Note: To read more on the
innerHTML
property anddocument.getElementById()
method, please refer to the following links:
Free Resources