location Posted on 2016-08-21 Location1Location 对象实际上是 JavaScript 对象,而不是 HTML DOM 对象,下面我们了解一下他的一些属性方法: 1location <br/> 1234567891011121314151617181920212223//注:要在服务器下打开//设置或返回完整的 URLvar url = location.href;document.write('url - ' + url + '<br />');//location.href = 'https://www.baidu.com/'//设置或返回从井号 (#) 开始的 URL(锚)var hash = location.hash;document.write("hash - "+ hash + '<br />');//设置或返回当前 URL 的主机名var hostName = location.hostname;document.write("hostName - "+ hostName + '<br />');//设置或返回当前 URL 的路径部分var pathname = location.pathname;document.write("pathname - "+ pathname + '<br />');//设置或返回当前 URL 的端口号var port = location.port;document.write("port - "+ port + '<br />');//设置或返回当前 URL 的协议var porocol = location.porocol;document.write("porocol - "+ porocol + '<br />');//设置或返回从问号 (?) 开始的 URL(查询部分)var search = location.search;document.write("search - "+ search + '<br />');