检测何时加载iframe中的特定元素 [英] Detect when a particular element in an iframe is loaded

查看:81
本文介绍了检测何时加载iframe中的特定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检测 iframe 中的特定元素何时加载而不等待加载完整的iframe内容?

Is there a way for me to detect when a particular element within an iframe is loaded without waiting for the full iframe content to load?

我遇到的问题是iframe中充满了许多SVG按钮,这些按钮需要很长时间才能加载和处理并挂钩到iframe的load事件中,强制我要采取的操作等待他们完全加载。我想从iframe中访问一个元素,并想知道是否有可能检测到该元素已加载而不等待iframe的全部内容加载。

The problem I have is that the iframe is filled with many SVG buttons that take a long time to load and process and hooking into the load event of the iframe forces the action I want to take to wait for them to load fully. I want to access one element out of the iframe and wanted to know if it was possible to detect that that element has been loaded without waiting for the full contents of the iframe to load.

JavaScript或jQuery解决方案都是我的文件。

JavaScript or jQuery solutions are both file with me.

推荐答案

$('iframe').onload = function() {
     alert("loaded")
})

这将在HTML加载时触发,但在完全解析和渲染之前会激活。

This will fire when the HTML is loaded, but before it has been fully parsed and rendered.

除此之外,你必须进行民意调查才能看到您要查找的元素位于页面中。

Beyond that you'd have to poll to see of the element you're looking for is in the page.

这篇关于检测何时加载iframe中的特定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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