-
2021-06-11 10:36:51
在web前端制作中,可以通过javascript获取当前网页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、设置或获取location或URL的hostname和port号码
window.location.host
7、设置或获取href属性中跟在问号后面的部分
window.location.search
8、获取变量的值(截取等号后面的部分)
var url = window.location.search;
alert(url.length);
alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);
9、获取当前网页的域名
document.domain
更多相关内容 -
js如何准确获取当前页面url网址信息
2021-01-19 15:20:35在WEB开发中,时常会用到javascript来获取当前页面的url网址信息,在这里是我的一些获取url信息的小总结。 下面我们举例一个URL,然后获得它的各个组成部分:http://i.cnblogs.com/EditPosts.aspx?opt=1 1、[removed... -
JavaScript获取当前url根目录(路径)
2020-11-23 15:19:12主要用到Location 对象,包含有关当前 URL 的信息,是 Window 对象的一个部分,可通过 [removed] 属性来访问。 方法一、js获取项目根路径的方法 function getRootPath(){ var curPageUrl = [removed].href; var ... -
js获取当前页面url网址信息
2021-05-26 09:31:40js获取当前页面url网址信息 var url; url = window.location.href; /* 获取完整URL */ alert(url); /* http://127.0.0.1:8020/Test/index.html#test?name=test */ url = window.location.pathname; /* 获取...js获取当前页面url网址信息
var url; url = window.location.href; /* 获取完整URL */ alert(url); /* http://127.0.0.1:8020/Test/index.html#test?name=test */ url = window.location.pathname; /* 获取文件路径(文件地址) */ alert(url); /* /Test/index.html */ url = window.location.protocol; /* 获取协议 */ alert(url); /* http */ url = window.location.host; /* 获取主机地址和端口号 */ alert(url); /* http://127.0.0.1:8020/ */ url = window.location.hostname; /* 获取主机地址 */ alert(url); /* http://127.0.0.1/ */ url = window.location.port; /* 获取端口号 */ alert(url); /* 8020 */ url = window.location.hash; /* 获取锚点(“#”后面的分段) */ alert(url); /* #test?name=test */ url = window.location.search; /* 获取属性(“?”后面的分段) */ alert(url); /* 如果需要URL中的某一部分,可以自己进行处理 */ url = window.location.pathname; url = url.substring(url.lastIndexOf('/') + 1, url.length); alert(url); /* /index.html */ /* * 如果页面使用了框架(frameset) * 要获取到指定页面的URL * 只要把window换成指定的页面即可 */ /* 'frame'为指定页面的class名 */ var url = window.parent.frames['frame'].location.href; /* 获取当前地址栏中显示的URL */ var url = window.parent.location.href; /* window parent 可互换 */ var url = parent.window.location.href;
-
js获取当前页面的url网址信息
2020-10-25 19:39:57主要介绍了通过js如何获取当前页面的url网址信息,需要的朋友可以参考下 -
php获取当前页面完整URL地址
2020-12-18 23:43:33下面提供一个用于获取当前页面URL的函数以及使用方法: 示例一: <?php // 说明:获取完整URL function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $... -
在asp.net中获取当前页面的URL的方法(推荐)
2021-01-21 19:19:371、通过C#获取当前页面的URL string url = Request.Url.AbsoluteUri; //结果: //www.jb51.net/web/index.aspx string host = Request.Url.Host; //结果:www.jb51.net string rawUrl = Request.RawUrl; //结果:/... -
JS 当前页面打开URL页面
2019-04-26 01:09:18NULL 博文链接:https://onestopweb.iteye.com/blog/2355605 -
JS获取当前页面的URL信息(获取页面url参数)
2020-12-05 20:18:44保存用 window.location.pathname 设置或获取对象指定的...设置或获取整个 URL 为字符串。 例:http://localhost:8080/demo/index?uid=119 输出:http://localhost:8080/demo/index?uid=119 window.location.por保存用
window.location.pathname
设置或获取对象指定的文件名或路径。例:http://localhost:8080/demo/index?uid=119
输出:/demo/index
window.location.href
设置或获取整个 URL 为字符串。例:http://localhost:8080/demo/index?uid=119
输出:http://localhost:8080/demo/index?uid=119
window.location.port
设置或获取与 URL 关联的端口号码。例:http://localhost:8080/demo/index?uid=119
输出:8080
window.location.protocol
设置或获取 URL 的协议部分。例:http://localhost:8080/demo/index?uid=119
输出:http:
window.location.hash
设置或获取 href 属性中在井号“#”后面的分段。
这个属性可以在一些单页应用很好的使用例:http://localhost:8001/#/login
输出:#/login
window.location.host
设置或获取 location 或 URL 的 hostname 和 port 号码。例:http://localhost8080/demo/index?uid=119
输出:localhost:8080
window.location.search
设置或获取 href 属性中跟在问号后面的部分。例:http://localhost:8080/demo/index?uid=119
输出:?uid=119
属性 描述 hash 设置或获取 href 属性中在井号“#”后面的分段 host 设置或获取 location 或 URL 的 hostname 和 port 号码 hostname 设置或获取 location 或 URL 的主机名称部分 href 设置或获取整个 URL 为字符串 pathname 设置或获取对象指定的文件名或路径 port 设置或获取与 URL 关联的端口号码 protocol 设置或获取 URL 的协议部分 search 设置或获取 href 属性中跟在问号后面的部分 -
PHP获取当前页面完整URL的方法
2020-09-01 02:02:57在大家在使用PHP编写程序的时候...下面就给大家分享了PHP获取当前页面完整URL的方法,文中还给出了如获取域名或主机地址、获取网页地址和包含端口号的完整url等的方法,有需要的朋友们可以参考借鉴,下面来一起看看吧。 -
nodejs实现获取当前url地址及url各种参数值
2021-01-01 18:39:52当前url http://localhost:8888/select?aa=001&bb=002 var http = require(‘http’); var URL = require(‘url’); http.createServer(function(req, res){ var arg = url.parse(req.url).query; //方法一arg =... -
JS - 获取当前页面的 url地址 及 相关信息
2020-12-31 12:20:49JS - 获取当前页面的 url地址 及 相关信息JS - 获取当前页面的 url地址 及 相关信息
一. 获取当前页面的 url地址
window.location
以
http://localhost:8080/home?id=123
地址为例- url 地址
方法:
window.location.href
结果: http://localhost:8080/home?id=123 - 地址协议
方法:
window.location.protocol
结果: http: - 域名 + 端口
方法:
window.location.host
结果: localhost:8080 - 域名
方法:
window.location.hostname
结果: localhost - 域名
方法:
window.location.port
结果: 8080 - 路径
方法:
window.location.pathname
结果: /home - 请求的参数
方法:
window.location.search
结果: ?id=123 - 协议 + 域名 + 端口
方法:
window.location.origin
结果: http://localhost:8080
二. 获取当前网址url 后的指定参数
// 获取当前网址url 后的指定参数 function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } return null; } //https://www.baidu.com/?tn=48021271_15_hao_pg let res = getQueryString("tn"); console.log(res);
- url 地址
-
JS 获取当前页面的URL
2019-04-23 01:54:34NULL 博文链接:https://onestopweb.iteye.com/blog/2292540 -
js如何获取当前页面url网址信息
2022-01-27 10:09:54在WEB开发中,时常会用到javascript来获取当前页面的url网址信息,在这里是我的一些获取url信息的小总结。 下面我们举例一个URL,然后获得它的各个组成部分:http://i.cnblogs.com/EditPosts.aspx?opt=1 1、window.... -
JS 获取当前页面url(不含参数)
2022-03-02 17:45:12// 不含参数 var url = window.location.protocol+"//"+window.location.host+""+window.location.pathname; // 整个url var url = window.location.href -
js获取当前页面url信息
2019-01-20 05:42:00js获取当前页面url信息 ``` <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>&... -
JS实现获取当前URL和来源URL的方法
2020-10-21 16:21:22主要介绍了JS实现获取当前URL和来源URL的方法,涉及javascript针对页面document属性操作的相关技巧,需要的朋友可以参考下 -
js获取当前页面url路径携带的参数
2021-09-27 16:35:16前端系统经常会出现系统嵌套的情况,参数由别的系统携带的情况,自然参数也是可以正常获取的 egg: 路径: // var str = 'http://baidu/#/home?user=aaa&role=bbb' var name, value; var objUrlParams = {} ... -
js获得当前url,javascript获取当前页面url值,js获取域名
2021-06-08 15:10:43thisURL = document.URL;thisHREF = document.location.href;thisSLoc = self.location.href;thisDLoc = document.location;strwrite = "thisURL:[" + thisURL + "]"strwrite += "thisHREF:[" + thisHREF + "]"strwr... -
js获取url页面id,也就是最后的数字文件名
2020-10-14 17:37:13主要介绍了js获取url页面id,也就是最后的数字文件名,有时候我们需要判断当前页面的id,又不用重新生成页面直接用js获取最后的数字.htm即可 -
js获取当前页面的url
2021-11-18 11:17:42js获取当前页面的url: let url = window.location.href; -
JS获取当前页面的URL参数
2018-11-13 14:31:451.首先需要获取当前页面的URL,这个可以从 window.location.search 获取: ...//获取当前页面URL的从问号 (?) 开始的 URL(查询部分) var params = window.location.search; Location 对象属性 属性 ... -
JavaScript获取当前页面地址
2021-08-04 11:34:51console.log(window.location.href) //返回当前页面的 href (URL) window.location.hostname console.log(window.location.hostname)//返回(当前页面的)因特网主机的名称。例 blog.csdn.net window.location.... -
JS获取当前页面的URL(网址信息)
2021-08-20 10:58:16JS获取当前页面的URL(网址信息) <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script> let url; url = window.location....