jQuery - 页面加载(?)问题的序列 [英] jQuery - sequence of page load(?) issue

查看:92
本文介绍了jQuery - 页面加载(?)问题的序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑

修正如下,只需将高度和宽度设置为零来隐藏iframe:

Fixed as follows, simply hide the iframe by setting height and width to zero:

<iframe frameborder="0" id="frm" height="0" width="0"></iframe>

var frmurl ='http://www.bbc.co.uk';

jQuery(function($){
        $('#frm').attr('src', frmurl);
        var doc = $('#frm')[0].contentDocument;
        $(doc.body).html('This text should replace the BBC website');  
});

我的网站依赖第三方系统来更新数据库中的记录并显示确认消息。通过iFrame访问第三方系统。我想用我自己的替换确认消息。

My website relies on a third party system to update a record in a database and display a confirmation message. Access to the third party system is via an iFrame. I would like to replace the confirmation message with one of my own.

我使用jQuery并且iFrame正常工作,除了我的替换文本在之前非常短暂地显示第三方系统生成的确认消息会覆盖它。您可以在此jsFiddle 上看到示例。

I use jQuery and I have the iFrame working correctly except that my replacement text is displayed very briefly before the confirmation message generated by the third party system overwrites it. You can see an example at this jsFiddle.

如何确保我的文本不会被覆盖?我认为它与生成页面的事件序列有关吗?

How can I ensure that my own text isn't overwritten? I think it has to do with the sequence of events in which the page is generated?

<iframe frameborder="0" id="frm" scrolling="no" width="100%"></iframe>

var frmurl ='http://www.bbc.co.uk';

jQuery(function($){
        $('#frm').attr('src', frmurl);
        var doc = $('#frm')[0].contentDocument;
        $(doc.body).html('This text should replace the BBC website');   
});


推荐答案

更新< iframe> ; src属性基本上是一个显式请求,浏览器使用从给定URL获取的内容更新帧。因此,要求浏览器同时执行此操作并且不这样做是没有意义的:)

Updating the <iframe> "src" property is basically an explicit request that the browser update the frame with the content fetched from the given URL. Thus, it doesn't really make sense to ask that the browser both do that and not do that :)

然而,您可以做什么,将您的消息放在某处其他而不是< iframe> 。无论< iframe> 是否可见,HTTP交易都会有效,因此如果您不希望用户看到结果,您只需隐藏< iframe> 通过CSS等等。

What you can do, however, is put your message somewhere else instead of in the <iframe>. The HTTP transaction will work whether the <iframe> is visible or not, so if you don't want your user to see the results you can just hide the <iframe> via CSS or whatever.

这篇关于jQuery - 页面加载(?)问题的序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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