用js获取当前页面的url

1.获取当前或者指定页面的文件名或路径 window.location.pathname

2.设置或获取整个URl字符串 window.location.href

3.设置或获取URL相关的端口号 window.location.port

4.设置或获取URL的协议部分 window.location.protocol

5.获取href中"#"后面的部分 window.location.hash

6.设置或者获取URL的hostname或者port window.location.host

7.设置或者获取href属性中问号"?"后面的部分 window.location.search

时间: 2024-08-26 03:31:00

用js获取当前页面的url的相关文章

js获取当前页面的url网址信息小汇总

在WEB开发中,时常会用到javascript来获取当前页面的url网址信息,在这里是我的一些获取url信息的小总结. 下面我们举例一个URL,然后获得它的各个组成部分:http://i.cnblogs.com/EditPosts.aspx?opt=1 1.window.location.href(设置或获取整个 URL 为字符串) var test = window.location.href; alert(test); 返回:http://i.cnblogs.com/EditPosts.as

用js获取当前页面的url的相关信息方法

1. 当前页面的完整url获取方式: window.localtion.url; 2. pathname部分: window.location.pathname 3. 设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或获取与 URL 关联的端口号码. alert(window.location.port) 设置或获取 URL 的协议部分. aler

js获取当前页面的URL信息

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

js获取当前页面的url信息方法

例如网址:http://localhost:12085/My/OrderM.aspx 设置或获取对象指定的文件名或路径. alert(window.location.pathname) 输出结果:/My/OrderM.aspx 设置或获取整个 URL 为字符串. alert(window.location.href); 输出结果:http://localhost:12085/My/OrderM.aspx 设置或获取与 URL 关联的端口号码. alert(window.location.port

用JS获取当前页面的URL以及截取其中的字段

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

JS获取当前页面的URL

如果获取“当前”域名 host = window.location.host; url=document.domain; url = window.location.href; 取得完整url路径: 用以下代码可以完整研证结果: <table width=100% cellpadding=0 cellspacing=0 border=0 > <script> thisURL = document.URL; thisHREF = document.location.href; thi

c#怎么获取当前页面的url

c#怎么获取当前页面的url   C# code HttpContext.Current.Request.Url Request.ServerVariables["HTTP_HOST"] + Request.ServerVariables["SCRIPT_NAME"] Request.ApplicationPath: /testwebRequest.CurrentExecutionFilePath: /testweb/default.aspxRequest.File

如何用js得到当前页面的url信息方法(JS获取当前网址信息)

设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或获取与 URL 关联的端口号码. alert(window.location.port) 设置或获取 URL 的协议部分. alert(window.location.protocol) 设置或获取 href 属性中在井号“#”后面的分段. alert(window.location.hash) 设

js得到当前页面的url信息方法(JS获取当前网址信息)

1.设置或获取整个 URL 为字符串: window.location.href 2.设置或获取与 URL 关联的端口号码: window.location.port 3.设置或获取 URL 的协议部分 window.location.protocol 4.设置或获取 href 属性中跟在问号后面的部分 window.location.search 5.获取变量的值(截取等号后面的部分) var url = window.location.search;//    alert(url.lengt