一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

jquery/js获取当前页面url地址程序代码

时间:2022-11-14 22:02:42 编辑:袖梨 来源:一聚教程网


设置或获取对象指定的文件名或路径。
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 = "

"

strwrite += "

"

strwrite += "

"

strwrite += "

"

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 = "

"

strwrite += "

"

strwrite += "

"

strwrite += "

"

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 = "

"

strwrite += "

"

document.write( strwrite );

thisURL: [" + thisURL + "]
thisHREF: [" + thisHREF + "]
thisSLoc: [" + thisSLoc + "]
thisDLoc: [" + thisDLoc + "]
thisTLoc: [" + thisTLoc + "]
thisPLoc: [" + thisPLoc + "]
thisTHost: [" + thisTHost + "]
thisHost: [" + thisHost + "]
thisHPage: [" + thisHPage + "]
thisUPage: [" + thisUPage + "]

运行如下: 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]

window.location

属性 描述
hash 设置或获取 href 属性中在井号“#”后面的分段。
host 设置或获取 location 或 URL 的 hostname 和 port 号码。
hostname 设置或获取 location 或 URL 的主机名称部分。
href 设置或获取整个 URL 为字符串。
pathname 设置或获取对象指定的文件名或路径。
port 设置或获取与 URL 关联的端口号码。
protocol 设置或获取 URL 的协议部分。
search 设置或获取 href 属性中跟在问号后面的部分。

热门栏目