Jquery/javascript检测iframe是否可以加载
我有来自另一个服务器/域的带有 OpenX 广告的 iframe。
当此广告服务器发生问题时,主服务器不会加载全部内容,因为 openx 在 iframe 中加载的域没有响应。我一直认为 iframe 独立于主站点工作,但如果域根本不响应,它就不会工作...
无论如何,主站点可以以某种方式检测到 iframe 中的 url 没有响应并跳过加载 iframe 并显示其余部分网站的?
I have iframes with OpenX ads I server from another server/domain.
When something happens to this ad server the main server doesn't load whole contents because the domain that openx loads in iframe is not responding. I always thought that iframe works independently from the main site but it doesn't if the domain doesn't answer at all...
Anyway can main site detect somehow that a url in iframe is not responding and skips loading iframe and show the rest of the site?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
网站加载后加载 iFrame 怎么样?使用 jQuery(甚至使用 window.load 事件的纯 JavaScript)可以很容易地做到这一点。
因此,您不必“检测” iFrame 是否已加载,而是可以在网站的其余部分完成加载后加载它。 (抱歉过度使用“load”一词)
在 jQuery 中,您可以简单地将 url 附加到 document.ready 事件上的 iFrame。
空白 iFrame
简单的 jQuery,用于在 document.ready 上加载 URL
How about loading the iFrame once the website is loaded? It's pretty easy to do this using jQuery (or even plain javascript using the window.load event).
So rather than wanting to 'detect' whether the iFrame has loaded, you can load it AFTER the rest of the website has completed loading. (sorry for excessive use of word 'load')
In jQuery, you can simply attach the url to the iFrame on the document.ready event.
A blank iFrame
Simple jQuery to load the URL on document.ready
不幸的是,没有简单的方法可以做到这一点,除非它们是从同一个域提供的。我知道有一种方法可以让 iframe 内的 javascript 对它所包含的父文档执行一些操作,但我不太确定如何...
Unfortunately there is no easy way to do this unless they are served from the same domain. I know there is a way to get let the javascript inside the iframe perform some actions on the parent document it is contained in, but I am not really sure how...
这是不可能的,因为同源策略,在某些浏览器中存在一些“差距”。但这不会推荐!
It is not possible, because of Same origin policy, there are some "gaps" in some browsers. But this is not going to recommend!
可能无法获得最佳体验,但您可以制作本地重定向文件。就像这样:
然后 redir 页面就返回
这样,只要您的服务器正在响应,其他一切都会在 iframe 重定向时照常继续?
Might not make for the best experience, but you can make a local redirect file. something like:
then the redir page just returns
That way as long as your server is responding, everything else will continue as normal while the iframe redirects?
如果我没有 iframe 只是来自不同域的 javascript 怎么样?如果域没有响应,JavaScript 将阻止页面加载。有办法防止这种情况吗?
How about if I don't have iframe just javascript originating from different domain? If the domain is not responding javascript holds the page back not to load. Is there a way to prevent that?