引用写人写的一个url 解析器 github源码:https://github.com/websanova/js-url
$.url()工具方法,二个参数:
1、第一个参数为提取网址方式
2、第二个参数为网址
尝试一下>>
<script src="https://www.xiyueta.com/js/xiyueta.min.js"></script> <script>
var i, ii, val, str = '', args = [null, , 'domain', 'hostname', 'sub', '.0', '.1', '.2', '.-1', 'auth', 'user', 'pass', 'port', 'protocol', 'path', 'file', 'filename', 'filext', '1', '2', '3', '-1', 'query', '?', 'hash', '#']; for (i = 0, ii = args.length; i < ii; i++) { val = xiyueta.url(args[i], "https://www.xiyueta.com?query=hi&did=mai#hash=test&aa=bb"); xiyueta.log(args[i], (val ? (typeof val === 'object' ? JSON.stringify(val) : val) : '-')) }
</script>
null https://www.websanova.com?query=hi&did=mai#hash=test&aa=bb
undefined https://www.websanova.com?query=hi&did=mai#hash=test&aa=bb
domain websanova.com
hostname www.websanova.com
sub www
.0 -
.1 www
.2 websanova
.-1 com
auth -
user -
pass -
port 443
protocol https
path -
file -
filename -
filext -
1 -
2 -
3 -
-1 -
query query=hi&did=mai
? {"query":"hi","did":"mai"}
hash hash=test&aa=bb
# {"hash":"test","aa":"bb"}