链接内容为 http://x.xxx.com/xxxx.xxx?x=1
window.location.href(设置或获取整个 URL 为字符串)
返回值:http://x.xxx.com/xxxx.xxx?x=1
window.location.protocol(设置或获取 URL 的协议部分)
返回值:http:
window.location.host(设置或获取 URL 的主机部分)
返回值:x.xxx.com
window.location.port(设置或获取与 URL 关联的端口号码)
返回值:空字符(如果采用默认的80端口(update:即使添加了:80),那么返回值并不是默认的80而是空字符) 或者 类似于8080的端口号
window.location.pathname(设置或获取与 URL 的路径部分(就是文件地址))
返回值:/xxxx.xxx
window.location.search(设置或获取 href 属性中跟在问号后面的部分)
返回值:?x=1
window.location.hash(设置或获取 href 属性中在井号“#”后面的分段)
此示例中没有
var url1 = "链接";
// 端口
url.port;
// 端口协议
url.protocol;
// 路径名
url.pathname;
// 协议+主机名+端口
url.origin;
// 查询部分
url.search;
// 哈希
url.hash;
// 完整 URL
url.href;