开发者

Internet explorer Object doesn't support this property or method

I've got this code throwing an error from an iframe:

            function parentIframeResize()
        {
            var height = getParam('height');
            // This works as our parent's parent is on our domain..
            parent.parent.resizeIframe(height);
        }

Not concerned about the error at all. The problem is it stops other scripts from running. Firefox, chrome or any decent browser just keeps running the rest of the scripts. I need to s开发者_JAVA技巧uppress the error or make sure parent.parent exists before running the code.

In php I would write something like if(!empty(parent.parent) { //do stuff with parent.parent } to check if the object exists.

Yes, nested iframes is ugly O_o


Try,

if (parent.parent && parent.parent.resizeIframe) {
    // parent.parent exists and supports resizeIframe
    parent.parent.resizeIframe(height);
}

That should work and stop the errors.


You could wrap it up in a try/catch block:

function parentIframeResize() {
    try {
        var height = getParam('height');
        parent.parent.resizeIframe(height);
    } catch(err) {
        // do something to recover from the problem, or nothing to suppress it
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜