开发者

GMail getElementById('canvas_frame') returning null in Firefox

开发者 https://www.devze.com 2023-02-11 04:37 出处:网络
I have written the following javascript function which hangs up because it never seems to be able to find the canvas_frame element on a loaded GMail page (the compose page). This is begin called via t

I have written the following javascript function which hangs up because it never seems to be able to find the canvas_frame element on a loaded GMail page (the compose page). This is begin called via the XUL of a Firefox add-on. Any thoughts on what might be going on?

   开发者_运维问答init : function () {
        var frame, interval;
        frame = document.getElementById('canvas_frame');
        interval = setInterval(function() {
            if (frame) {
                if (frame.contentDocument) {
                    clearInterval(interval);
                    GLOBALS.doc = frame.contentDocument;
                    onContentReady();
                }
            }
        }, 500);
    }


You should prefer to wait for a load event on the frame, rather than polling. But my guess is that the canvas_frame element hasn't been created yet, so you need to fetch it each time inside the polling loop. Otherwise the frame variable is always null.

0

精彩评论

暂无评论...
验证码 换一张
取 消