父页面里两个iframe之间互相访问

来源:互联网 发布:name.com注册域名 编辑:程序博客网 时间:2024/06/05 19:18

 

父页面里的代码里的两个iframe

<iframe  id="frameLeft"  height="100%" src="UserDeptLeft.htm">

</iframe>
<iframe  id="frameRight" name="frameRight"  src="Default.htm"  height ="100%"></iframe>

 

左边的iframe 页里有控件:

<input  type="hidden"  id="moduleid" name="moduleid"/>

 

的iframe访的Iframe里的控件 moduleid

js 代码如下:

 parent.frameLeft.window.document.getElementById("moduleid")

 

页面访iframe里的控件 moduleid

js代码如下: 

window.frames["frameLeft"].document.getElementById("moduleid")


网搜知识:

IE7兼容Iframe高度問題及Iframe問題

<body>
    <iframe marginheight="0" marginwidth="0" src="Default.aspx" frameborder="0" scrolling="no" width="100%" id="info_iframe" name="info_content" onload="change_size()"></iframe>
</body>

 

<head>
  <script language="javascript">
    function change_size()
    {
        document.getElementById("info_iframe").style.height=info_content.document.body.scrollHeight+1+"px";
    } 
  </script>
</head>


防止被人frame  
  <SCRIPT   LANGUAGE=JAVASCRIPT><!--    
  if   (top.location   !=   self.location)top.location=self.location;  
  //   --></SCRIPT>

 

所谓自适应,是指iframe的高度,由iframe里的页面内容高度来决定,

并设置iframe的边框为0,

无滚动条, 这样就看不出iframe的真正的高度啦

上面的chang_size方法,应用不是太好,

又在网上查了资料

方法不错,放在blog里,为学习之用.

 

  function TuneHeight() {
    debugger;
        var frm = document.getElementById("frameLeft");
        var subWeb = document.frames ? document.frames["frameLeft"].document : frm.contentDocument;
        if(frm != null && subWeb != null) {
           frm.height = subWeb.body.scrollHeight;
        }

     <iframe  id="frameLeft" width ="25%" height="100%"   src="Left.htm" onload="TuneHeight()"></iframe>

原创粉丝点击