location的属性
/*href:完整的url地址*/ console.log(location.href); /*网络传输协议*/ console.log(location.protocol); /*主机名称*/ console.log(location.hostname); /*端口号*/ console.log(location.port); /*返回主机名和端口号*/ console.log(location.host); /*返回?以后的区域*/ console.log(location.search); /*返回锚点区*/ console.log(location.hash); /*返回页面的路径*/ console.log(location.pathname);
location的方法
function baidu() { /*加载新的页面,并且可以可以实现路径的点击回退*/ location.assign("http://www.baidu.com") } function reloadPage() { /*reload():重新加载当前页面 * reload(true):彻底的重新加载当前页面,不从缓存取东西*/ location.reload(true); } function replacePage() { /*加载新的页面,但是新页面完全把老页面替换,不能返回。*/ location.replace("http://www.baidu.com"); }