日期:2014-05-16  浏览次数:20308 次

JavaScript父窗口与子窗口之间的操作总结---window.open篇
window.open 篇


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;


关闭本窗口: