Blogger Information
Blog 91
fans 0
comment 0
visits 203547
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JavaScript父窗口与子窗口之间的操作总结---window.open篇
何澤小生的博客
Original
1684 people have browsed it

1.父窗口对子窗口操作

打开:

var win=null; 
win=window.open("Open.html","win","width=200,height=200");

 最大化: 

//窗口最大化

function SonMaximize() 
{ 
       if(win&&win.open&&!win.closed) 
       { 
              win.moveTo(-4,-4); 
              win.resizeTo(screen.availWidth+8,screen.availHeight+8); 
       }else{ 
              alert('还没有打开窗口或已经关闭'); 
       } 
}

最小化:
//窗口最小化

function SonMinimize() 

{ 
       if(win&&win.open&&!win.closed) 
       { 
              win.resizeTo(0,0); 
              win.moveTo(0,window.screen.width); 
       }else{ 
       alert('还没有打开窗口或已经关闭'); 
       }     
}

关闭: 

//关闭窗口

function CloseSon() 
{ 
       if(win&&win.open&&!win.closed) 
       { 
              win.opener=null; 
              win.close() 
       }else{ 
              alert('还没有打开窗口或已关闭') ; 
       } 
}

刷新: 

//刷新

function RefreshSon() 
{ 
       if(win&&win.open&&!win.closed) 
       { 
              win.location.reload(); 
              win.focus(); 
       }else{ 
              alert('窗口还没有打开或已关闭'); 
       } 
}

查看窗口大小:

function ViewSonSize() 

{ 
       if(win&&win.open&&!win.closed) 

       { 
              alert(win.document.body.clientWidth+'*'+win.document.body.clientHeight); 
              win.focus(); 
       }else 
       { 
              alert(' 还没有打开窗口或者已关闭'); 
       }     
}

取值: 

alert(window.document.getElementById("OpenDiv").innerHTML);

赋值: 

win.document.getElementById("OpenDiv").innerHTML="我是从父窗口中传过来的值";


2.子窗口操作窗口

刷新: 

window.opener.location.reload(); 
       //下面这种方法也可以 
       //window.parent.location.href=window.parent.location.href;

关闭本窗口: 

//关闭本窗口

function CloseWindow() 

{     //window.opener.opener=null; 
       window.close(); 
}

关闭父窗口: 

//关闭父窗口 

function CloseParent() 
{     //火狐下不起作用,如果要想起作用。用下面的方法 

     //开firefox,在地址栏输入about:config       
       //找到dom.allow_scripts_to_close_windows这项并改为true 
              var IsIE = (navigator.appName == 'Microsoft Internet Explorer') 
              if(IsIE){//如果是IE             
                     window.opener.opener=null; 
                     window.opener.close(); 
                     window.close();      
              }else{ 

                     alert("火狐不能直接关闭;需要以下设置1.开firefox,在地址栏输入about:config;2.找到dom.allow_scripts_to_close_windows这项并改为true"); 
              } 
}

取值: 

alert(window.opener.document.getElementById("OpenDiv").innerHTML);

赋值: 

window.opener.document.getElementById("OpenDiv").innerHTML="我是从子窗口Open传过来的值";



原网站链接:http://blog.csdn.net/cui55/article/details/52574584

如有版权因素请联系管理员:2929006594(qq) , 15811405490( tel )。


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post