日期:2014-05-17  浏览次数:20390 次

如何调用子窗口的函数
a.aspx 代码:
VB.NET code

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>主页面</title>
    <script type ="text/javascript" language ="javascript" >
        function callfun()
        {
            //调用子窗口函数showmsg();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Button1" type="button" value="call subfrm" onclick ="callfun()" />
        <iframe id="subfrm" src="b.aspx"></iframe>
    </div>
    </form>
</body>
</html>



b.aspx 代码:
VB.NET code

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>子页面</title>
    <script type ="text/javascript" language ="javascript" >
        function showmsg()
        {
            alert("call by mainfrm!");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>



如何调用
我用window.frames["subfrm"].showmsg(); 提示错误

------解决方案--------------------
document.all.subfrm.contentWindow.showmsg()
------解决方案--------------------
document.frames.subfrm.showmsg();也可以 但不是window.frames
------解决方案--------------------
IFRAME嵌套b.aspx
window.frames[txtFrame].showmsg()