iframe 主父窗口函数调用

45 篇文章 0 订阅
37 篇文章 0 订阅

1.iframe 主父窗口函数调用

方式一:window.frames["frm1"].a();

方式二:window.htmlletter.a();

ps:frm1是iframe的id;a()是引用页面中的函数名


demo:

1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<table>
<tr>
       
            <td colspan="10" align="center">
           记录内容
              </td>  
            
   </tr>         
        
     
 <iframe src="2.html" id="frm1" name="frm1"></iframe>
<input type="button" value="run inner page's function" οnclick='window.frames["frm1"].a();' />
</table>
<div id="id1" style="display:none; width:90px; height:80px;">
<form method="post">
    <input type="file" />
    <button type="button" >submit</button>
    </form>
</div>
<script>

alert(document.getElementsByName("frm1")[0].src );
</script>
</body>
</html>


2.

2.html


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="Untitled-2.js"></script>
</head>
<style type="text/css">
table{
    border-top:1px solid #FF00FF;
border-right:1px solid #0000FF;
border-bottom:0px double #FF00FF;
border-left:0px solid #FF0000;

}
tr{
    border-bottom:none;
}
td{
    border:1px solid #CCCCCC;
}
</style>
<body>
<table>
<tr>
       
            <td colspan="10" align="center">
           记录内容
              </td>  
            
   </tr>         
        
       <tr>
       <td>                                       
            <a href="javascript:void(0)" οnclick="parent.document.getElementById('id1').style.display='';">添加图片</a>
            
              </td>  
          
      
         <tr>

</table>
</body>
</html>

3.Untitled-2.js

// JavaScript Document
function a(){
alert("s");
}
function getParentEl(){
    parent.document.getElementById("id1").style.display="";
    alert(parent.document.title);
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值