window.onbeforeunload = function(){
  event.cancelBubble = false;
  event.returnValue = '请点"取消"以保证网页显示在框架内'; //或者'请点"取消"'
}我本来想用以上这种方式,但是这种方式实在太不友好,而且无法判断该事件onbeforeunload是由iframe中网页触发还是本网页链接触发

解决方案 »

  1.   

    没错,暂时没做跨浏览器,我们头说微软捐给祖国2亿美元,国内网民绝大多数都用IE,所以除非万不得已,是不情愿做跨IE之外的浏览器的
      

  2.   

    没仔细看if (top.location != self.location) {top.location=self.location;}
    这句本身是有问题的在 [A] 页面中设一个参数,名字叫 location ,不用赋值
    top.location=self.location
    这句就变成了给  top 中的 location 参数赋值后遗症是,如果你的 [A] 也有 frame 层次结构,其他调用 top.location 的时候,也会出问题没时间仔细测,只是 IE 的话应该可以吧
      

  3.   

    刚才没时间仔细写:[A.htm]:<html>
    <head>
    </head> <body>
    this is A.htm
    <br>
    <iframe src="B.htm"></iframe>
    </body> <script>
    var location;
    </script>
    </html>[B.htm]:<html>
    <head>
    </head> <body>
    this is B.htm
    </body> <script>
    if (top.location != self.location) {
    top.location=self.location;
    } else {
    }
    </script>
    </html>
    旁门左道的应用,只有这种旁门左道的解决了
    没测,有问题告诉我
      

  4.   

    如果A和B都是你自己的很好作,要不是,别想了B 显然是别人的A 应该是自己可以控制的