首先举个例子,下面是一个URL:http://60.191.28.90:8484/p4/backer/yz_admin/web/index.php?r=whole-data
1. window.location.href(设置或获取整个URL字符串)
var test_url = window.location.href;
alert(test_url);
返回:http://60.191.28.90:8484/p4/backer/yz_admin/web/index.php?r=whole-data
2. window.location.protocol(设置或获取URL的协议部分)
var test_url = window.location.protocol;
alert(
test_url);
返回:http:
3. window.location.host(设置或获取URL的主机部分)
var test_url = window.location.host;
alert(test_url);
返回:
60.191.28.90
4. window.location.port(设置或获取URL使用的端口号)
var test_url = window.location.port;
alert(test_url);
返回:8484 (如果采用默认的80端口,返回值并不是80,而是空字符)
5. window.location.pathname(设置或获取URL中文件的路径,包含文件名)
var test_url = window.location.pathname;
alert(test_url);
返回:/p4/backer/yz_admin/web/index.php
6. window.location.search(设置或获取URL中“?”后面的参数)
var test_url = window.location.search;
alert(test_url);
返回:?r=whole-data