当iframe加载时,如何使iframe在主页上运行Javascript函数?
我有这个HTML:当iframe加载时,如何使iframe在主页上运行Javascript函数?,javascript,jquery,html,ajax,ajax-upload,Javascript,Jquery,Html,Ajax,Ajax Upload,我有这个HTML: <script type="text/javascript"> function uploadDone(response) { alert(response); } function init() {
<script type="text/javascript">
function uploadDone(response) {
alert(response);
}
function init() {
document.getElementById('file_upload_form').onsubmit=function() {
document.getElementById('file_upload_form').target = 'upload_target'; //'upload_target' is the name of the iframe
document.getElementById("upload_target").onload = uploadDone(response);
}
}
</script>
<form method="get" id="file_upload_form" enctype="multipart/form-data" action="../includes/parsecsv.ajax.php" target="upload_target">
<label class="uploadClick">
<button class="normal">Click to Upload Sign Ups CSV</button>
<input type="file" id="uploadSignups file" name="file">
</label>
<span class="uploadDrag"><span>or</span>Drag Your Sign Ups CSV Here</span>
<button type="submit" name="action">hello</button>
<iframe id="upload_target" name="upload_target" src="" style="width:0px; height:0px; border:none;"></iframe>
</form>
函数上传完成(响应){
警报(响应);
}
函数init(){
document.getElementById('file\u upload\u form')。onsubmit=function(){
document.getElementById('file_upload_form')。target='upload_target';//'upload_target'是iframe的名称
document.getElementById(“upload_target”).onload=uploadDone(响应);
}
}
单击以上载注册CSV
在这里注册CSV
你好
当您单击submit按钮时,它应该通过
将所选文件以轴向方式上传到文件输入中。我似乎能够让它进行上传,但上传完成后,它似乎没有运行uploadDone()
?有什么问题吗?我想您只需要在iFrame的窗口元素中添加一个事件:
document.getElementById("upload_target").contentWindow.onload = function(response) { uploadDone(response) };
另外,请注意,我将
uploadDone
包装在一个函数中;否则,它将调用它并将事件设置为它返回的任何内容。使用IFrame的父属性,在这里,您需要创建一个JSP文件,该文件将包含响应和
在JSP中编写一些脚本以访问uploadDone
方法,该方法已加载到文档中
JSP中的脚本可以类似于:
parent.document.uploadDone(response);
表单包含enctype=multipart/Form数据,但不包含method=post。正常提交时使用方法=GET,而不使用enctype。-当您的uploadDone()函数触发时,请不要在SO中使用SMS speak('Here,u need');把单词完整地拼出来。