由于iframe导致的问题
Issue due to iframe
我在一个jsp表单中有两个单选按钮(遍历和直接)。traverse用于正常提交表单,direct用于使用iframe汇总表单。使用iframe提交表单后,如果我尝试正常提交,则应用程序将在新窗口中打开。如何防止表单在新窗口中打开。
function submitAction() {
var fileValue = document.getElementById("file1").value;
if (fileValue == "") {
alert("Please uploaded file type of .war or .html type");
return false;
}
var valuePassed = getCheckedRadio();
var url="uploadfile.do?rad=" + valuePassed;
if (valuePassed == "traverse") {
document.EntryForm.action = url;
document.EntryForm.submit(); //Normal way of submitting.
}else if (valuePassed == "direct") {
alert("direct");
url=url+"&fileName="+fileValue;
directConvert(document.EntryForm,url,'downloaddiv'); }
}
function directConvert(form, action_url, div_id){
// Create the iframe...
var iframe = document.createElement("iframe");
iframe.setAttribute("id", "upload_iframe");
iframe.setAttribute("name", "upload_iframe");
iframe.setAttribute("width", "0");
iframe.setAttribute("height", "0");
iframe.setAttribute("border", "0");
iframe.setAttribute("style", "width: 0; height: 0; border: none;");
// Add to document...
form.parentNode.appendChild(iframe);
//window.frames['upload_iframe'].name = "upload_iframe";
iframeId = document.getElementById("upload_iframe");
// Add event...
var eventHandler = function () {
if (iframeId.detachEvent) iframeId.detachEvent("onload", eventHandler);
else iframeId.removeEventListener("load", eventHandler, false);
// Message from server...
if (iframeId.contentDocument) {
content = iframeId.contentDocument.body.innerHTML;
} else if (iframeId.contentWindow) {
content = iframeId.contentWindow.document.body.innerHTML;
} else if (iframeId.document) {
content = iframeId.document.body.innerHTML;
}
document.getElementById(div_id).innerHTML = content;
// Del the iframe...
setTimeout('iframeId.parentNode.removeChild(iframeId)',50);
}
if (iframeId.addEventListener) iframeId.addEventListener("load", eventHandler, true);
if (iframeId.attachEvent) iframeId.attachEvent("onload", eventHandler);
// Set properties of form...
form.setAttribute("target", "upload_iframe");
form.setAttribute("action", action_url);
form.setAttribute("method", "post");
form.setAttribute("enctype", "multipart/form-data");
form.setAttribute("encoding", "multipart/form-data");
form.submit();
}
当我第一次尝试遍历时,它工作正常,但在通过iframe提交后,如果我尝试遍历,它将在新窗口中打开。如何防止它在新窗口中打开。
因为您将EntryForm
的form
对象传递给iframe,并在执行directConvert
提交时更改form.setAttribute("target", "upload_iframe");
。
因此,即使尝试通过traverse
提交,form
目标也保持不变,但由于iframe
已从页面中删除(setTimeout('iframeId.parentNode.removeChild(iframeId)',50);
),因此在提交后会在新窗口中打开,而不是iframe
。
因此,您可以在traverse
submit:document.EntryForm.target = "_self"
中将target
改回_self
。
顺便说一句,target
属性在HTML 4.01中已被弃用。
相关文章:
- 由于iframe导致的问题
- 使用YouTube iFrame API的IE中的JavaScript问题
- 将HTML表单发布到iframe会导致浏览器历史记录出现问题
- 从父页面调用iframe中的javascript,IE问题
- 在Google Chrome中打印iFrame时出现问题
- 在Internet Explorer 8中的Iframe中创建TinyMCE时出现问题
- 这个基于iFrame选择器的if函数有什么问题
- 当内容显示在FireFox的iFrame中时,jQuery高度问题
- 如何应对iframe安全问题
- 使用 Iframe 问题设置跨域 Cookie
- 移动设备上的 iFrame 重定向主页问题
- iframe 的奇怪跨域问题
- Iframe 透明度问题
- 缺少 iframe ie8.相对定位不能解决问题
- HTML5验证中漂亮的照片iframe的问题
- 检测 iframe 中的连接问题
- Firefox 13 iframe 打印问题来自 JavaScript
- insertBefore() 一个 iframe jquery 问题
- 未捕获的安全错误端口问题:Iframe调整大小
- fanybox的问题.Iframe只适用于网站上的第一个链接