知识汇总03~iframe页面之间的跳转

页面跳转的方法: 
假如有A,B,C三个页面,C是B的iframe, B是A的iframe
第一种:本页面的跳转
location = window.location =location.href = window.location.href =self.location.href = "url地址";
window.open("url地址","_self");1212

第二种:父页面的跳转
parent.location.href=window.parent.location.href=window.parent.window.location"url地址";
window.open("url地址","_parent");1212

第三种:祖父页面的跳转
parent.parent.location=top.location.href=window.top.location.href"url地址";
window.open("url地址","_top")==parent.open("url地址","_parent")=parent.parent.open("url地址","_self");1212

第四种:子页面的跳转
将iframe的src修改即可,如:<iframe src="D.html" name="sonIframe">;
window.sonIframe.location="D.html";1212

第五种:孙子页面的跳转
window.sonIframe.grandsonIframe.location="D.html";
window.sonIframe.document.getElementById('grandsonIframeId').src="D.html";1212

第六种:超链接<a>的跳转
<a href="D.html" target="_self">跳转到D.html页面</a> /*默认_self是在本窗口跳转*/
window.open("url地址","_blank");//默认_blank是在新窗口跳转1212

注意:可以通过设置target属性,实现不同方式的跳转页面。
多个嵌套iframe之间的相互访问全局变量和全局函数
第一种:子iframe的访问
调用方法:window.sonIframe.ff();
调用变量:window.sonIframe.vv;1212

第二种:父iframe的访问
调用方法:window.parent.ff();
调用变量:window.parent.vv;1212

第三种:最外层iframe的访问
调用方法:window.parent.parent.ff();
调用变量:window.top.vv;1212

第四种:平级iframe的访问
top.frames["sonIframeone"].sonIframeone("调用平级的另一个iframe的方法");

猜你喜欢

转载自www.cnblogs.com/sunshineForFuture/p/9342066.html