用‘http://example.com:8000/pathname?search=test#hash’为例:
let queryUrl = function (url = window.location.href) { let _url = document.createElement('a'); _url.href = url; return { protocol :_url.protocol,//'http' host :_url.host,//'example.com:8000' hostname :_url.hostname,//'example.com' port :_url.port ? _url.port :'80',//'8000', pathname : _url.pathname,//'/pathname/' search :_url.search,//'?search=test' hash :_url.hash,//‘#hash’ } }
调用方法queryUrl,可以获取url中的信息。
若参数url为空,则默认去当前浏览器的url作为参数。
转载于:https://www.cnblogs.com/xiaoqd/p/9072078.html
原文链接:https://blog.csdn.net/weixin_30342827/article/details/99956247
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~