首先我们了解一下:window.location.href、location.href、self.location.href、parent.location.href、top.location.href他们的区别与联系,简单的说:几种location.href的区别 js实现网页被iframe框架功能
"window.location.href"、"location.href"、"self.location.href"是本页面跳转
"parent.location.href"是上一层页面跳转
"top.location.href"是最外层的页面跳转
举个例子说明(如上图):
如果A,B,C,D都是普通页面,D是C的iframe,C是B的iframe,B是A的iframe,
如果D中js这样写:
"window.location.href"、"location.href":D页面跳转
"parent.location.href":C页面跳转
"top.location.href":A页面跳转
如果D页面中有form的话: