常用属性:
(1)location.href
返回当前加载页面的完整URL
location.href=window.location.href
(2)location.hash
返回URL中的hash(#后)
如果不包含则返回空字符
eg:页面最下设置一个button为返回顶部,添加一个id=“top"后
var btn=document.getElementById(‘top’);
btn.οnclick=function(){
location.hash="#top";
}
(3)location.host
功能:返回服务器名称和端口号(如果有)
(4)location.hostname
功能:返回不带端口号的服务器名称。
(5)location.pathname
功能:返回URL中的目录和(或)文件名。
(6)location.port
功能:返回URL中指定的端口号,如果没有,返回空字符串。
(7)location.protocol
功能:返回页面使用的协议。
(8)location.search
功能:返回URL的查询字符串。这个字符串以问号开头。