最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

browser - What is the difference between document.baseURI and document.URL in javascript - Stack Overflow

matteradmin2PV0评论

I always saw in developer tool that the both the entities(baseURI and URL) shows the same URL, which is shown in address bar most of the time. Can someone provide me the scenarios when those are different and when do we use one over other. I have seen the description of mdn website but still confused regarding those two terms.

I always saw in developer tool that the both the entities(baseURI and URL) shows the same URL, which is shown in address bar most of the time. Can someone provide me the scenarios when those are different and when do we use one over other. I have seen the description of mdn website but still confused regarding those two terms.

Share Improve this question asked Sep 9, 2018 at 5:31 GhanshamGhansham 4981 gold badge6 silver badges20 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

For most intended purposes, it is the same. But it can differ in some scenarios.

  1. If you use a <base> tag in the HTML document. Lets say, you use the following HTML tag,

<base href = "https://example" />

Check the https://jsfiddle/kqbL0c4f/

and your URL is https://example/123 Your document.URL and document.baseURI would differ.

https://developer.mozilla/en-US/docs/Web/HTML/Element/base

The <base> HTML element specifies the base URL to use for all relative URLs in a document. There can be only one <base> element in a document.

  1. If you create a document dynamically
Post a comment

comment list (0)

  1. No comments so far