在JavaScript中,使用location对象可以通过很多方式来改变浏览器的位置。看看W3C上的描述location的一句话
Note: There is no public standard that applies to the location object, but all major browsers support it.
大意是location对象没有标准定义,但主流浏览器都支持
看看以下例子看你掌握了几种
/**
* JavaScript位置location对象操作例子
* 琼台博客 www.qttc.net
*/
// 假设初始URL为 https://www.qttc.net/lee/
// 将URL修改为 https://www.qttc.net/lee/#top
location.hash = '#top';
// 将URL修改为 https://www.qttc.net/lee/?q=php
location.search = '?q=php';
// 将URL修改为 https://www.lizhong.me/lee/
location.hostname = 'www.lizhong.me';
// 将URL修改为 https://www.qttc.net/dir/
location.pathname = 'dir';
// 将URL修改为 https://www.qttc.net:8888/lee/
location.port = 8888;
...