jQuery对话框iframe在IE中加载一次,在其他浏览器加载两次? [英] jQuery dialog iframe loading once in IE and twice in other browsers?

查看:161
本文介绍了jQuery对话框iframe在IE中加载一次,在其他浏览器加载两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery对话框,其内容由iframe定义。在显示对话框之前,此iframe的内容是不可见的。在IE中,此内容及其关联的javascript正在执行,因此当显示对话框时,很明显javascript已经完成了所有加载工作。但是在Firefox和Chrome之类的非IE浏览器中,这个iframe再次在对话框可见之前执行其javascript,但显然重新 - 在显示对话框时执行它。

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.

因为这是一个相当昂贵的iframe(使用ajax调用执行大量javascript),我不希望浏览器支付初始化两次的费用。事实上,我可能会说我想延迟初始化它,直到对话框实际出现。但是它是否在它启动之前初始化然后保留初始化(如IE正在进行)或它只是延迟初始化直到对话框可见,我可以解决。

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 initializes 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.

我不能满足的是我现在看到的,非IE浏览器初始化两次,第一次是完全浪费,因为它们在对话框出现时重新初始化。

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.

我所指的页面: http://openidux.dotnetopenauth.net/。您可以通过单击右上角的登录链接来重现行为。

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.

谢谢。

推荐答案

我最初将iframe.src属性设置为about:blank,并且仅在对话框实际弹出时设置源。然后,为了避免在对话框隐藏时重新加载(愚蠢,我知道),我将其重新设置为about:blank。

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;
        },
    });
});

这篇关于jQuery对话框iframe在IE中加载一次,在其他浏览器加载两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆