onload功能在Chrome中不适用于iFrame

时间:2013-03-01 11:49:20

标签: javascript google-chrome iframe extjs onload

我有一个onload事件,用于检测iFrame是否已完成加载。它在FF中运行良好但在Chrome或IE中没有任何想法吗?

<html>
<head>
    <title>Iframe onload event</title>
    <link rel="stylesheet" type="text/css" href="../../ext-4.2.0-beta/resources/css/ext-all.css">
    <script type="text/javascript" src="../../ext-4.2.0-beta/ext-all-debug.js"></script>
</head>
<body>
    <script type="text/javascript">
    Ext.onReady(function(){
        //create a button
        Ext.create('Ext.button.Button',{
            text: 'Open Iframe',
            handler: function(){
                //try to get a reference to an already existing iframe
                var dlIframe = Ext.get('CSMREP_DOWNLOAD_IFRAME');

                //destroy the iframe if already exists
                if(dlIframe){
                    dlIframe.destroy();
                }

                var mask = Ext.getBody().mask('iframe loading...');

                //add an iframe to download the report
                var iframe = Ext.DomHelper.append(Ext.getBody(),
                '<iframe id="CSMREP_DOWNLOAD_IFRAME" src="iframe.php" style="display:none;"></iframe>');

                iframe.onload = function(){
                    Ext.getBody().unmask();
                };
            },
            renderTo: Ext.getBody()
        });
    });
    </script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

为什么你不这样做:http://ext4all.com/post/detect-iframe-load-event?这样你就可以使用ExtJS监听器了。