从iFrame中触发javascript事件 [英] trigger javascript event from within an iFrame
问题描述
我不确定这是否可行,但我有一个小型Web应用程序负责将文件上传到服务器。此应用程序由另一个应用程序使用,该应用程序将其包含在iFrame中。
I am not sure if this is possible but I have a small web application that is responsible for uploading files to the server. This app is used by another app which includes it in an iFrame.
上传者应用程序正在使用jQuery表单在后台提交文件,我希望能够在上传完成和成功回调时通知父应用程序火灾。
The uploader app is using jQuery form to submit the file in the background and I would like to be able to notify the parent app when the upload is complete and the success callback fires.
我正在考虑以某种方式将一个函数传递到可以从父母调用的iFrame应用程序但是我不确定如何执行此操作或者它是否均匀可能。
I was thinking about somehow passing a function into the iFrame app that could be called from the parent but I am not sure how to do this or if it is even possible.
推荐答案
我不确定正确方式是做什么的,但你可以在父框架中写一些类似 document.callback = function(){...}
的内容,并且 parent.document.callback()$ c你的iframe中的$ c>。
I'm not sure what's the right way to do this, but you can write something like document.callback = function() { ... }
in your parent frame and parent.document.callback()
in your iframe.
当然,父框架/ iframe中的网页必须来自同一个域或浏览器才会阻止它们之间的任何互动。
Of course your pages in parent frame/iframe must be from the same domain or browser will block any interaction between them.
这篇关于从iFrame中触发javascript事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!