*chrome浏览器需要在服务器环境中测试

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <div id="d1"></div>
        <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"> </script>
        <script>
            $(function() {
                var iframe = '<iframe >;
                $("#d1").html(iframe);
                onIframeLoaded(f1,function() {
                    executeIframeFun("a");
                });
            
                /**
                 *     iframe加载成功事件
                 **/
                function onIframeLoaded(iframe,onload) {
                    if (iframe.attachEvent) {
                        iframe.attachEvent("onload", function() {
                            onload();
                        });
                    } else {
                        iframe.onload = function() {
                            onload();
                        };
                    }
                }
                /**
                 * 执行iframe的方法
                 * funName 方法名
                 */
                function executeIframeFun(funName) {
                    if (window.frames['f1'].contentWindow) {
                        window.frames['f1'].contentWindow[funName]();
                    } else {
                        window.frames['f1'][funName]();
                    }
                }
            
            });
        </script>
    </body>
</html>

iframe html:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        子页面
        <script type="text/javascript">
            function a(){
                alert('子页面');
            }
        </script>
    </body>
</html>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2021-07-08
  • 2022-12-23
  • 2021-12-08
  • 2021-09-15
  • 2022-01-05
  • 2022-01-29
  • 2021-08-29
相关资源
相似解决方案