国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
總結(jié)JavaScript(Iframe、window.open、window.showModalDialog)父窗口與子窗口之間的操作

一、Iframe


//&&&&&&&&&&&&&&&&&&&&公共方法開始&&&&&&&&&&&&&&&

//父對(duì)象得到子窗口的值

//ObjectID是窗口標(biāo)識(shí),ContentID是元素ID

function GetValue(ObjectID,ContentID)

{

       var IsIE = (navigator.appName == 'Microsoft Internet Explorer')

                     if(IsIE)

                     {//如果是IE         

                            alert(document.frames(ObjectID).document.getElementById(ContentID).innerHTML);                              

                     }

                     else

                     {//如果是FF

                             alert(document.getElementById(ObjectID).contentDocument.getElementById(ContentID).innerHTML);

                                   //FF下不支持innerText; 下面是解決方法                     

                                   //if(document.all){

                                   //  alert(document.getElementById('div1').innerText);

                                   //} else{

                                   //  alert(document.getElementById('div1').textContent);

                                   //}

                     }    

}

 

//父對(duì)象向子窗口賦值

//ObjectID是窗口標(biāo)識(shí),ContentID是元素ID

function SetValue(ObjectID,ContentID)

{

var IsIE = (navigator.appName == 'Microsoft Internet Explorer')

              if(IsIE)

              {//如果是IE         

                     document.frames(ObjectID).document.getElementById(ContentID).innerHTML="我是IE下通過父窗口賦值過來的";                            

              }

              else

              {//如果是FF

                      document.getElementById(ObjectID).contentDocument.getElementById(ContentID).innerHTML="我是FF下通過父窗口賦值過來的";                  

              }    

}

//&&&&&&&&&&&&&&&&&&&&公共方法結(jié)束&&&&&&&&&&&&&&&

 

 

      1.父窗口對(duì)子窗口操作

 

刷新:

      document.getElementById("IframeID").src=document.getElementById("IframeID").src+"?_="+Math.random();

上面這種方法有時(shí)需要對(duì)“src”屬性處理一下。

 

取值:

//父窗口取子窗口的值

       GetValue("Iframe1","IframeDiv");

 

賦值:

//父窗口設(shè)置窗口元素的值;

       SetValue("Iframe1","IframeDiv");      

 

   2.子窗口操作父窗口

 

              刷新:

           (1)、window.parent.location.href=window.parent.location.href;  

           (2)、window.parent.location.reload();

              (3)、大家可以補(bǔ)充

 

    取值:

alert(window.parent.document.getElementById("IframeDiv").innerHTML);    

 

賦值:

window.parent.document.getElementById("IframeDiv").innerHTML="我是從子窗口IFRAME傳過來的值";

 

關(guān)閉:

window.parent.opener=null;//如果不加這句,會(huì)提示關(guān)閉詢問窗口;

window.parent.close();

二、window.open

1.父窗口對(duì)子窗口操作

打開:

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('還沒有打開窗口或已經(jīng)關(guān)閉');

       }

}

 

最小化:

//窗口最小化

function SonMinimize()

{

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

       {

              win.resizeTo(0,0);

              win.moveTo(0,window.screen.width);

       }else{

       alert('還沒有打開窗口或已經(jīng)關(guān)閉');

       }    

}

 

 

 

關(guān)閉:

//關(guān)閉窗口

function CloseSon()

{

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

       {

              win.opener=null;

              win.close()

       }else{

              alert('還沒有打開窗口或已關(guān)閉') ;

       }

}

 

刷新:

//刷新

function RefreshSon()

{

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

       {

              win.location.reload();

              win.focus();

       }else{

              alert('窗口還沒有打開或已關(guān)閉');

       }

}

 

查看窗口大?。?/span>

function ViewSonSize()

{

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

       {

              alert(win.document.body.clientWidth+'*'+win.document.body.clientHeight);

              win.focus();

       }else

       {

              alert(' 還沒有打開窗口或者已關(guān)閉');

       }    

}

 

取值:

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

 

賦值:

win.document.getElementById("OpenDiv").innerHTML="我是從父窗口中傳過來的值";

 

2.子窗口操作窗口

 

刷新:

window.opener.location.reload();

       //下面這種方法也可以

       //window.parent.location.href=window.parent.location.href;

 

 

 

 

 

關(guān)閉本窗口:

//關(guān)閉本窗口

function CloseWindow()

{     //window.opener.opener=null;

       window.close();

}

 

關(guān)閉父窗口:

//關(guān)閉父窗口

function CloseParent()

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

    //firefox,在地址欄輸入about:config      

       //找到dom.allow_scripts_to_close_windows這項(xiàng)并改為true

              var IsIE = (navigator.appName == 'Microsoft Internet Explorer')

              if(IsIE){//如果是IE            

                     window.opener.opener=null;

                     window.opener.close();

                     window.close();     

              }else{

                     alert("火狐不能直接關(guān)閉;需要以下設(shè)置1.firefox,在地址欄輸入about:config;2.找到dom.allow_scripts_to_close_windows這項(xiàng)并改為true");

              }

      

}

 

取值:

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

 

賦值:

window.opener.document.getElementById("OpenDiv").innerHTML="我是從子窗口Open傳過來的值";           

 

三、模態(tài)窗口篇

1.父窗口操作子窗口

父窗口JS代碼:

var parValue="現(xiàn)在顯示了父窗口中的變量值";

var hao="郝建衛(wèi)";

function ShowDailog(PageHref,Title,Height,Width)

{

       //--------------left位置

       //screen.availHeight聲明了顯示瀏覽器的屏幕的可用寬度

       var dleft =(screen.availHeight-Height)/2;

       //--------------top位置

       var dtop =(screen.availWidth-Width)/2;

       //---------------

 

Var sRet = window.showModalDialog(PageHref,window,Title,"scrollbars=yes;resizable=no;help=no;status=no;center=yes;dialogTop=25;dialogLeft="+ dleft +";dialogTop="+ dtop +";dialogHeight="+Height+"px;dialogWidth="+Width+"px;");

       //--------return

       if (sRet =="refresh")//這種是利用返回值來刷新父頁(yè)面

       {

              window.Test="true";

              window.location.reload();            

              alert(window.Test);

       }

}

function test()

{

       alert("模態(tài)窗口成功調(diào)用父窗口的方法");

}

2.模態(tài)窗口操作父窗口

var parentWin=window.dialogArguments; 

 

刷新:

       parentWin.location.reload(); 

 

取值:

alert(parentWin.document.getElementById("ShowModalDialogDiv").innerHTML)   //獲取父窗口中的對(duì)象

 alert("我是從父窗口中得到的變量>>>"+parentWin.parValue);       //獲取父窗口中的變量

 

調(diào)用父窗口JS方法:

parentWin.test();    //調(diào)用父窗口中的方法

 

賦值:

parentWin.document.getElementById("ShowModalDialogDiv").innerHTML="我是從子窗口ShowModalDialog傳過來的值";      

 

關(guān)閉本窗口:

//關(guān)閉本窗口

function CloseWindow()

{

       window.parent.close();

}

 

關(guān)閉父窗口:

//關(guān)閉父窗口

function CloseModal()

{    

       var IsIE = (navigator.appName == 'Microsoft Internet Explorer')

              if(IsIE){//如果是IE            

                     window.parent.parent.close();

                     //parentWin.opener=null;如果把上面的換成這行,不能關(guān)閉父窗口,

                     parentWin.close();

                     //window.parent.parent.parent.parent.close();這個(gè)只能關(guān)閉模態(tài)窗口本身目前只在IE6下測(cè)試

              }else{

                     alert("火狐不能直接關(guān)閉;需要以下設(shè)置1.firefox,在地址欄輸入about:config;2.找到dom.allow_scripts_to_close_windows這項(xiàng)并改為true");

              }    

}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
iframe 父子傳參通信
JS動(dòng)態(tài)更改iframe框架的SRC屬性值,適用于跳轉(zhuǎn)新窗口的時(shí)候使用
中醫(yī)古籍
extjs 組件打印 問題
JS 常用命令
jQuery 實(shí)現(xiàn)iframe 自適應(yīng)高度
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服