使用 Javascript 和跨域 iframe
我有一个 iframe,可以将另一个站点的表单加载到我的站点中(我控制这两个域,但它们是不同的)。
iframe 被加载到我网站上的 fancybox 中,我希望它在处理 iframe 中的表单时弹出一个 AJAX 加载图形。
我知道我无法直接将事件侦听器添加到其他站点的 iframe,但是有什么方法可以让我的站点知道 iframe 中发生了什么?
I have an iframe that loads a form from another site into my site (I control both domains but they are different).
The iframe is loaded into a fancybox on my site and I would like it to popup an AJAX loading graphic when the form in the iframe is processing.
I know I can't directly add event listeners to the iframe form other site but is there any way that my site can know what is going on in the iframe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,没有办法知道另一个 iframe 正在做什么。
让域(iframe 内的域)在内容显示之前加载 AJAX 加载图形,所有这些都在服务器端......您不需要为此使用客户端。
No there's no way of knowing what another iframe is doing.
Have the domain (the one inside the iframe) load the AJAX loading graphic before the content shows up, all on the server side... you don't need the client for this.
我同意 Luca 的观点,但是必须先加载您的表单,然后才能显示 AJAX 加载图形。如果它是一个非常大的表单,这可能需要一段时间,并且可能会破坏加载图形的目的。
您是否考虑过通过 javascript 加载表单内容,完全绕过 iframe?只需获取表单的内容并将其加载到 div 中? (当然,如果您加载的表单很复杂,可能会导致更多问题)
I agree with Luca, but then your form will have to be loaded before the AJAX loading graphic can be displayed. If it is a very large form, this might take a while and will perhaps defeat the purpose of the loading graphic.
Have you considered loading the contents of the form via javascript instead, bypassing the iframe altogether? Just GET the contents of the form and load it into a div? (Granted, if the form you're loading is complex, that might cause more problems)
浏览器绝对禁止了解 iframe 中发生的情况。
It is absolutely forbidden by browsers to know what is going on in the iframe.