设置或获取对象指定的文件名或路径。
window.location.pathname
设置或获取整个 URL 为字符串。
window.location.href
设置或获取与 URL 关联的端口号码。
window.location.port
设置或获取 URL 的协议部分。
window.location.protocol
设置或获取 href 属性中在井号“#”后面的分段。
window.location.hash
设置或获取 location 或 URL 的 hostname 和 port 号码。
window.location.host
设置或获取 href 属性中跟在问号后面的部分。
window.location.search
window.location 属性 描述 hash 设置或获取 href 属性中在井号“#”后面的分段。
host 设置或获取 location 或 URL 的 hostname 和 port 号码。
hostname 设置或获取 location 或 URL 的主机名称部分。
href 设置或获取整个 URL 为字符串。
pathname 设置或获取对象指定的文件名或路径。
port 设置或获取与 URL 关联的端口号码。
protocol 设置或获取 URL 的协议部分。
search 设置或获取 href 属性中跟在问号后面的部分。
设置或获取对象指定的文件名或路径。
| 代码如下 | 复制代码 |
设置或获取整个 URL 为字符串。
| 代码如下 | 复制代码 |
|
alert(window.location.href); |
|
设置或获取与 URL 关联的端口号码。
| 代码如下 | 复制代码 |
设置或获取 URL 的协议部分。
| 代码如下 | 复制代码 |
设置或获取 href 属性中在井号“#”后面的分段。
| 代码如下 | 复制代码 |
设置或获取 location 或 URL 的 hostname 和 port 号码。
| 代码如下 | 复制代码 |
设置或获取 href 属性中跟在问号后面的部分。
| 代码如下 | 复制代码 |
如果获取“当前”域名
host = window.location.host;
url=document.domain;
url = window.location.href;
取得完整url路径: 用以下代码可以完整研证结果:
| 代码如下 | 复制代码 |
|
thisURL = document.URL; thisHREF = document.location.href; thisSLoc = self.location.href; thisDLoc = document.location; strwrite = " | |
| thisURL: | [" + thisURL + "] |
strwrite += "
thisHREF: [" + thisHREF + "] "strwrite += "
thisSLoc: [" + thisSLoc + "] "strwrite += "
thisDLoc: [" + thisDLoc + "] "document.write( strwrite );
thisDLoc = document.location;
thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
strwrite = "
thisTLoc: [" + thisTLoc + "] "strwrite += "
thisPLoc: [" + thisPLoc + "] "strwrite += "
thisTHost: [" + thisTHost + "] "strwrite += "
thisHost: [" + thisHost + "] "document.write( strwrite );
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
tmpHPage = thisHREF.split( "/" );
thisHPage = tmpHPage[ tmpHPage.length-1 ];
tmpUPage = thisURL.split( "/" );
thisUPage = tmpUPage[ tmpUPage.length-1 ];
strwrite = "
thisHPage: [" + thisHPage + "] "strwrite += "
thisUPage: [" + thisUPage + "] "document.write( strwrite );
运行如下: thisDLoc = document.location;
thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
thisURL: [http://w*eibo*.com/*js/jsweibourl.html]
thisHREF: [http://w*eibo*.com/*js/jsweibourl.html]
thisSLoc: [http://w*eibo*.com/*js/jsweibourl.html]
thisDLoc: [http://w*eibo*.com/*js/jsweibourl.html]
thisTLoc: [http://w*eibo*.com/*js/jsweibourl.html]
thisPLoc: [http://w*eibo*.com/*js/jsweibourl.html]
thisTHost: [weibo.com]
thisHost: [weibo.com]
thisHPage: [jsweibourl.html]
thisUPage: [jsweibourl.html]
| 属性 | 描述 |
|---|---|
| hash | 设置或获取 href 属性中在井号“#”后面的分段。 |
| host | 设置或获取 location 或 URL 的 hostname 和 port 号码。 |
| hostname | 设置或获取 location 或 URL 的主机名称部分。 |
| href | 设置或获取整个 URL 为字符串。 |
| pathname | 设置或获取对象指定的文件名或路径。 |
| port | 设置或获取与 URL 关联的端口号码。 |
| protocol | 设置或获取 URL 的协议部分。 |
| search | 设置或获取 href 属性中跟在问号后面的部分。 |