javascript跨框架显示div

来源:互联网 发布:必备的办公软件 编辑:程序博客网 时间:2024/06/05 10:20

项目中碰到需要跨框架显示div的问题,百度了一下,搜集了一下群众的智慧,特整理出下面这个例子,先看看效果图:

 

本例共有4个页面:

index.html

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style>.popDiv{position:absolute;float:left;width:300px;height:300px; background-color:#f7f7f7;top:50;left:25;display:none;z-index:2;}</style></head> <body>         <div id='popId' class='popDiv'>the test div float over iframe.</div>         <iframe src="frame.html" width=100% height=100% marginwidth=0></iframe> </body> </html>

 

frame.html

<frameset rows="74,*" cols="*" style="z-index:1">        <frame src="frame-top.html" style="z-index:1">        <frame src="frame-main.html" style="z-index:1"> </frameset><noframes></noframes>

 

frame-top.html

<a href="#" onclick="top.document.getElementById('popId').style.display='block'">show div</a>


frame-main.html

I'm main frame

页面建立好,直接打开index.html即可看到效果。具体原理就是通过在父页面设置好div,从frame内部调用父页面的div来显示
1 0
原创粉丝点击