javascript操作iframe小记

来源:互联网 发布:快速密码读取软件 编辑:程序博客网 时间:2024/06/13 08:47

今天写完了由每个频道的复制相同的权限,使用 javascript操作iframe

1.事先应该想好DIV的布局,多个DIV在一起的话,应该由DIV包含在一个DIV里面,这样会自动向下排.

2.提交按钮为了方便可以不写在form表单里面,而应该写出一个button,函数中包含form.submit()

3.对于window.setTimeout(function(){},50),如果包含参数的话,则直接写在function 里面,setTimeout中的函数不能包含参数,如:window.setTimeout(function(){var li_index=la_divid[z++];  putDivArea(toDivs[li_index], la_city);},i*(la_city.length)*40);

4.window.setTimeout只是延时执行,那么其它的代码会先执行,包括它后面的代码,但执行的时间中的参数是延时前的值,函数里面的值是延时后的值

5.表单提交到iframe的form参数中也是有post,和get,只不过要包含target="iframe的name",其实实现无刷新就是通过webservice,ajax,iframe

6.iframe操作父类窗口是var win=window.parent,如window.parent.document.createElement("li");

7.如果要添加的checkbox的checked为true的话,则要在添加所有元素之后再设置checkbox.checked=true,下面的代码是没有办法运行的,

 input.checked = true
  div.appendChild(input)
    document.body.appendChild(input)
//input.checked = true

只有将input.checked放在appenchild后才能执行


8.iframe自动收缩:在iframe的页面中加入<body onload="autoheight();">,然后再加如下javascript代码

 

function autoheight()
    
{
        
//var iframe=window.parent.document.getElementById("keyword");           
          //iframe.height   =   iframe.document.body.offsetHeight; 
         if(self!=top )
         

               
var   iframe   =   parent.document.getElementById(window.name);   
              iframe.height   
=   10;   
              iframe.height   
=   document.body.scrollHeight;           
          }

    }
原创粉丝点击