轉 iframe 子 父類視窗操作

2021-06-23 09:24:10 字數 3848 閱讀 1183

一、

iframe 

篇原部落格**:

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

//父物件得到子視窗的值

//objectid是視窗標識,contentid是元素id

function getvalue(objectid,contentid)

else

else

}    

}//父物件向子視窗賦值

//objectid是視窗標識,contentid是元素id

function setvalue(objectid,contentid)

else

}//&&&&&&&&&&&&&&&&&&&&公共方法結束&&&&&&&&&&&&&&&

1.父視窗對子視窗操作

重新整理:

document.getelementbyid("iframeid").src=document.getelementbyid("iframeid").src+"?_="+math.random();

上面這種方法有時需要對「src」屬性處理一下。

取值:

//父視窗取子視窗的值

getvalue("iframe1","iframediv");

賦值:

//父視窗設定視窗元素的值;

setvalue("iframe1","iframediv");      

2.子視窗操作父視窗

重新整理:

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

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

(3)、大家可以補充

取值:

alert(window.parent.document.getelementbyid("iframediv").innerhtml);    

賦值:

window.parent.document.getelementbyid("iframediv").innerhtml="我是從子視窗iframe傳過來的值";

關閉:

window.parent.opener=null;//如果不加這句,會提示關閉詢問視窗;

window.parent.close();

二、

window.open 

1.父視窗對子視窗操作

開啟:

var win=null;

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

最大化:

//視窗最大化

function sonmaximize()

else

}最小化:

//視窗最小化

function sonminimize()

else    

}關閉:

//關閉視窗

function closeson()

else

}重新整理:

//重新整理

function refreshson()

else

}檢視視窗大小:

function viewsonsize()

else

}取值:

alert(window.document.getelementbyid("opendiv").innerhtml);

賦值:

win.document.getelementbyid("opendiv").innerhtml="我是從父視窗中傳過來的值";

2.子視窗操作視窗

重新整理:

window.opener.location.reload();

//下面這種方法也可以

關閉本視窗:

//關閉本視窗

function closewindow()

關閉父視窗:

//關閉父視窗

function closeparent()

else

}取值:

alert(window.opener.document.getelementbyid("opendiv").innerhtml);     

賦值:

window.opener.document.getelementbyid("opendiv").innerhtml="我是從子視窗open傳過來的值";           

三、模態視窗篇

1.父視窗操作子視窗

父視窗js**:

var parvalue="現在顯示了父視窗中的變數值";

var hao="郝建衛";

function showdailog(pagehref,title,height,width)

}function test()

2.模態視窗操作父視窗

var parentwin=window.dialogarguments; 

重新整理:

parentwin.location.reload(); 

取值:

alert(parentwin.document.getelementbyid("showmodaldialogdiv").innerhtml)   //獲取父視窗中的物件

alert("我是從父視窗中得到的變數》"+parentwin.parvalue);       //獲取父視窗中的變數

呼叫父視窗js方法:

parentwin.test();    //呼叫父視窗中的方法

賦值:

parentwin.document.getelementbyid("showmodaldialogdiv").innerhtml="我是從子視窗showmodaldialog傳過來的值";      

關閉本視窗:

//關閉本視窗

function closewindow()

關閉父視窗:

//關閉父視窗

function closemodal()

else    

}

iframe 父視窗和子視窗的呼叫方法

父視窗呼叫子視窗 iframe id.iframe document object.object attribute attribute value 例子 onclick iframe text.myh1.innertext 子視窗呼叫父視窗 parent.parent document objec...

iframe 父視窗和子視窗的呼叫方法

父視窗呼叫子視窗 iframe id.iframe document object.object attribute attribute value 例子 onclick iframe text.myh1.innertext http www.pint.com 子視窗呼叫父視窗 parent.par...

HTML中IFrame父視窗與子視窗相互操作

一 iframe篇 公共方法開始 父物件得到子視窗的值 objectid是視窗標識,contentid是元素id function getvalue objectid,contentid else else 父物件向子視窗賦值 objectid是視窗標識,contentid是元素id functio...