开发者

jQuery dialog iframe loading once in IE and twice in other browsers?

开发者 https://www.devze.com 2022-12-10 10:26 出处:网络
I have a jQuery dialog whose content is defined by an iframe.Until the dialog is displayed, the content of this iframe is invisible.In IE, this content and its associated javascript is executing, so t

I have a jQuery dialog whose content is defined by an iframe. Until the dialog is displayed, the content of this iframe is invisible. In IE, this content and its associated javascript is executing, so that when the dialog is displayed, it is evident that the javascript has already completed all its loading work. But in non-IE browsers like Firefox and Chrome, this iframe is, again, executing its javascript before the dialog is visible, but then apparently re-executes it when the dialog is shown.

Because this is a fairly expensive iframe to create (lots of javascript executes with ajax calls and all), I don't want the browser to pay the cost of initializing it twice. In fact, I might say I want to delay initializing it until the dialog is actually brought up. But whether it in开发者_如何转开发itializes before it's brought up and then preserves that initialization (as IE is doing) or it just delays initialization until the dialog is visible, I could settle for either.

What I can't settle for is what I'm seeing now, where non-IE browsers initialize twice, with the first time being a total waste since they're reinitialized when the dialog appears.

The page I'm referring to: http://openidux.dotnetopenauth.net/. You can repro the behavior by clicking the Login link in the upper-right corner.

Thanks.


I ended up setting the iframe.src property to "about:blank" initially, and only set the source when the dialog actually pops up. And then, to avoid it reloading when the dialog hides (stupid, I know), I set it back to about:blank.

$(document).ready(function() {
    $("#loginDialog").dialog({
        close: function(event, ui) {
            // Clear the URL so Chrome/Firefox don't refresh the iframe when it's hidden.
            iframe.src = "about:blank";
        },
        open: function(event, ui) {
            iframe.src = loginContent;
        },
    });
});


I had the same problem just now. I found the problem to be linked to the animation option when opening the dialog, it seems to interfere with the iframe. Just remove the "show" settings from your javascript.

change this

$("#blah").dialog({ title: 'Dialog Title', show: 'slide', .... }); 

to this

$("#blah").dialog({ title: 'Dialog Title', ... });


I haven't taken a deep look into the link, but what kind of onload event are you using to initialize the IFRame? Could it be a onDomLoad / onLoad issue?

0

精彩评论

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