属性 | 描述 |
hash | 从#开始的url |
host | 主机名和当前url端口号 |
hostname | 当前URL主机名 |
search | ?及以后的参数 |
href | 完整的URL |
pathname | 当前URL路径部分 |
port | 端口号 |
protocol | 当前URL协议 |
对url进行编码解码
编码:encodeURIComponent方法
解码:decodeURIComponent方法
案例
var uri = "https://www.runoob.com/my test.php?name=ståle&car=saab";
var a= encodeURIComponent(uri);
document.write(a)
document.write('<br>')
document.write(decodeURIComponent(a))
结果: