【JavaScript】iframe間(Iframe父頁面和子頁面之間)參數傳遞
假設父頁面(Ex︰A.html),子頁面(Ex︰B.html)。
父頁面(Ex︰A.html)
Javascript︰
<script type="text/javascript">
//父回應
function parentResponse(s)
{
alert('parentResponse---'+s);
}
//呼叫子
function callchild(s)
{
window.frames["childframe"].childResponse(s);
}
</script>
HTML︰
<input name="callChild" type="button" onclick="callchild('son');" value="呼叫子"/>
<br/>
<iframe src="B.html" name="childframe" width="100%" marginwidth="0" marginheight="0" scrolling="No" frameborder="0" id="childframe" ></iframe>
============================================================================================
子頁面(Ex︰B.html)
Javascript︰
<script type="text/javascript">
//子回應
function childResponse(s)
{
alert('childReponse---'+s);
}
//呼叫父
function callparent(s)
{
var frame = window.parent;
while(frame != frame.parent && frame.name != "app_frame") {
frame=frame.parent;
}
frame.parentResponse(s);
}
</script>
HTML︰
<hr /> '分隔線
<input name="callParent" type="button" onclick="callparent('Dady');" value="呼叫父"/>
執行畫面(初始化)︰

執行畫面(呼叫子)︰

執行畫面(呼叫父)︰

留言
張貼留言