I'm using the hidden iframe method to submit a form with a file upload field. I want to display a message back on the page using javascript and I'm not sure how to do this. If this was just a form with text fields I'd do an AJAX post and respond with a message I'd display in my callback function. I'm just not sure how to accomplish this same task with the hidden iframe method since it is a standard form post.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Inside the iframe, when your server responds after finishing the upload, you can include some onload Javascript in there that references the parent
frame.
Alternatively, you could attach an onload listener to the iframe itself from within the parent page. If you add this listener after the iframe initially loads, it should not fire until the next load (which would be after the upload completes).
回答2:
Enclose your iframe HTML in <div onload="javascript:window.parent.your_handler();"> ... </div>