这里是引用
window.location()是只能在一个网站中打开本网站的网页
window.open()是可以在一个网站上打开另外的一个网站的地址
当嵌套在页面内使用跳转时
"top.location.href" 最外层的页面跳转(当前页面跳转)
"window.location.href"、"location.href" 本页面跳转(内层部分单独跳转)
"parent.location.href" 是上一层页面跳转(父级页面)
location是window对象的属性,而所有的网页下的对象都是属于window作用域链中(这是顶级作用域),所以使用时是可以省略window。而top是指向顶级窗口对象,parent是指向父级窗口对象。
window.location或window.open如何指定target?
这是一个经常遇到的问题,特别是在用frame框架的时候
解决办法:
window.location 改为 top.location 即可在顶部链接到指定页
或
window.open("你的网址","_top");
例子
<input type="button" value="新窗口打开" onclick="window.open('http://www.baidu.com')">
<input type="button" value="当前页打开" onclick="top.location='http://www.baidu.com' ">```