top.location和location.href的区别
转自:http://www.cnblogs.com/liangyu/articles/2530884.html top.location.href=”url” 在顶层页面打开url(跳出框架) self.location.href =”url” 仅在本页面打开url地址 parent.location.href=”url” 在父窗口打开Url地址 this.location.href=”url” 用法和self的用法一致 if (top.location == self.location) 判断当前location 是否为顶层 来禁止frame引用,如果页面当中有自定义的frame的话,也可以将parent self top换为自定义frame的名称 ,效果就是在自定义frame窗口打开url。 实际中可能这样使用: 1 if ( top !== self ){ 2 3 top . location . href = location . href ; 4 5 } // 禁止frame引用 以下是从网上找到的一个例子,不是很直观, 我加了上面那三行代码, 可以先去掉, 再加上, 看一下效果,就很清楚了。 top.htm 代码: 1 < script language = javascript > 2 3 function rs (){ 4 5 if