document.domian document.URL document.baseURI(Node.baseURI) document.documentURI location.href
document.domain location.host location.origin
- document.domian
- document.URL
- document.baseURI(Node.baseURI)
- document.documentURI
- location.href
- document.domain
- location.host
- location.origin
网络页面(本页)的location:host,hostname,href,origin,pathname
本地文件页面的location:host,hostname,href,origin,pathname
网络的document.domian
本地的document.domian是空字符串
domian域名 hostname主机名
网络
本地文件
host 和 hostname 的区别:
host带port(80不显示), hostname不带
location.hostname 和 document.domain 的区别
document.URL , document.documentURI , location.href , node.baseURI
document.URL
返回当前文档的 URL 地址
该属性的值和DOM Level 0 中的document.location.href 属性的值是相等的。然而 document.location.href 是可写的,document.URL 是只读的。
document.documentURI 也返回与该属性相同的值,不过它在非 HTML 文档中也可以使用。
document.documentURI
Document 接口的属性 documentURI 以字符串的形式返回文档的位置(location)。在最初的 DOM3 定义中,这个属性是可读/写的。在现代的 DOM 标准(DOM4)中,它是只读的。
HTML 文档有一个 document.URL 属性返回同样的值。但是不像 URL,documentURI 适用于所有类型的文档。
location.href
Location 接口的 href 属性是一个字符串化转换器 (stringifier), 返回一个包含了完整 URL 的 USVString 值,且允许 href 的更新。
document.location.href和document.location.replace都可以进入指定页面
document.location.href切换后,回退按钮有效
document.location.replace切换后,回退无效
Node.baseURI(document.baseURI)
Node.baseURI 是只读属性,返回一个节点的绝对基址 URL。
当浏览器要获取绝对 URL 时,就需要用基 URL 去解析相对 URL。例如,解析 HTML 元素的 src 属性时,或者 处理 XML xlink:href 属性时—。
一般情况下,基 URL 是 document 的 location,但是它受诸多方面因素的影响,例如 HTML 的 元素和 XML xml:base (en-US) 属性。
document.URL 和 location.href 的区别
document.URL只读 , location.href可以再赋值
document.URL属性的值和DOM Level 0 中的document.location.href 属性的值是相等的。然而 document.location.href 是可写的,document.URL 是只读的。
document.URL 属于比较老的 api, 作为代替应该尽量使用 window.location.href 而非 document.URL.
document.URL 和 document.baseURI 的区别
document.URL 是document专有的
document.baseURI 是 node.baseURI … head,body等元素节点都有baseURI属性
一般来说 document.URL===document.baseURI
<base>:文档根 URL 元素
HTML <base> 元素 指定用于一个文档中包含的所有相对 URL 的根 URL。一份中只能有一个 <base> 元素。
一个文档的基本 URL,可以通过使用 document.baseURI (en-US) 的 JS 脚本查询。如果文档不包含 <base> 元素,baseURI 默认为 document.location.href。