location对象

//对象中的属性和方法
//location 对象
console.log(window.location);


//地址栏上#及后面的内容
console.log(window.location.hash);
//主机及端口号
console.log(window.location.host);
//主机名
console.log(window.location.hostname);
//文件的路径----相对路径
console.log(window.location.pathname);
//端口号
console.log(window.location.port);
//协议
console.log(window.location.protocol);
//搜索的内容
console.log(window.location.search);


//设置跳转的页面地址
location.href="http://www.baidu.com";//属性-----
location.assign("http://www.baidu.com");//方法
location.reload();//重新加载
location.replace("http://www.baidu.com");//没有历史记录----不能返回原页面
原文地址:https://www.cnblogs.com/lujieting/p/10050467.html