Javascript 提交带有 iFrame 目标的表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5495519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Submitting a form with an iFrame target
提问by Ernest
I want to submit a form into an iFrame on the same page as the form. I'm using Target="iframe_results" where iframe_results is the name of the iframe.
我想将表单提交到与表单位于同一页面上的 iFrame 中。我正在使用 Target="iframe_results" 其中 iframe_results 是 iframe 的名称。
This works fine in Firefox and Chrome but in IE it pops open a new tab/window.
这在 Firefox 和 Chrome 中工作正常,但在 IE 中它会弹出一个新标签/窗口。
I tried using JavaScript to do the submits (as outlined in other sources) but this still didnt work.
我尝试使用 JavaScript 进行提交(如其他来源所述),但这仍然无效。
回答by JohnP
What version of IE are you using? I've implemented this method without having any issues whatsoever
你用的是什么版本的IE?我已经实现了这个方法,没有任何问题
http://www.openjs.com/articles/ajax/ajax_file_upload/
http://www.openjs.com/articles/ajax/ajax_file_upload/
<form id="file_upload_form" method="post" enctype="multipart/form-data" action="upload.php">
<input name="file" id="file" size="27" type="file" /><br />
<input type="submit" name="action" value="Upload" /><br />
<iframe id="upload_target" name="upload_target" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>
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
}
}