Javascript 当文件托管在http服务器上时,IE 11将表单发布到新窗口不起作用
我的html中有一个表单Javascript 当文件托管在http服务器上时,IE 11将表单发布到新窗口不起作用,javascript,html,internet-explorer,Javascript,Html,Internet Explorer,我的html中有一个表单 在js文件中,当用鼠标单击表单提交按钮时,我打开了一个新窗口 win=window.open('about:blank','Frame','top='+top+',left='+left+',width='+width+',height='+height+',location=no,status=1,toolbar=0,menubar=0,resizable=1,scrollbars=1'); 然后我将这个表单的目标设置到新窗口中 document.getElem
在js文件中,当用鼠标单击表单提交按钮时,我打开了一个新窗口
win=window.open('about:blank','Frame','top='+top+',left='+left+',width='+width+',height='+height+',location=no,status=1,toolbar=0,menubar=0,resizable=1,scrollbars=1');
然后我将这个表单的目标设置到新窗口中
document.getElementsByName(“form1”)[0].target=“Frame”;
对于IE11以外的浏览器,这是有效的,表单post的响应显示在新窗口中。但在IE11上,这只有在我直接用浏览器打开html时才起作用。如果我在本地主机上提供html和js文件,表单post响应将显示在父窗口中,新打开的窗口将为空。
我认为这与IE11中的域检查有关,因为它只在我将其托管在服务器上时发生?
有人知道为什么吗?有没有人可以绕过这个问题?谢谢我发现解决您问题的唯一方法是克隆整个表单元素,隐藏它,使其不会显示,将其注入新窗口,然后提交 我使用了此javascript代码,在所有浏览器上都运行良好:
/**
* Sending form in a new window function
*/
function submitInNewWindow(event) {
// Prevents default so the form won't be submitted
event.preventDefault();
// SOme variables
var win, container;
// Opens the new window
win = window.open('about:blank', 'Frame', 'top=0, left=0, width=250, height=250, location=no, status=1, toolbar=0, menubar=0, resizable=1, scrollbars=1');
// Creates a container to hold the cloned form
container = win.document.createElement('div');
// Gets the form HTML and uses it as the container HTML
container.innerHTML = document.getElementById('form').outerHTML;
// Hides the container
container.style.display = 'none';
// Injects the container in to the new window
win.document.body.appendChild(container);
// Submits the new window form
win.document.querySelector('form').submit();
}
// Gets the form element
var form = document.getElementById('form');
// Attachs the event (for modern browsers)
if(typeof form.addEventListener === 'function') {
window.addEventListener('submit', submitInNewWindow, false);
}
// Attaches the event for old Internet Explorer versions
else {
form.attachEvent('onsubmit', submitInNewWindow);
}
HTML:
<form action="http://localhost/test/" id="form" name="form" method="post" target="Frame">
<input id="field1" name="field1" type="hidden" value="1234" />
<input id="field2" name="field2" type="text" value="5678" />
<input type="submit" value="send">
</form>
我已经在InternetExplorer11、Edge、Chrome(Mac/PC)、Firefox(Mac/PC)和Safari上进行了测试
希望有帮助 是否尝试更新策略配置 开放本地安全策略
在本地策略/安全选项分支下,启用“用户帐户控制:对内置管理员帐户使用管理员批准模式”。只需将
target=“\u blank”
放在
元素中,而不是使用脚本。我相信你的意思是target=“frame”,但我尝试了,但它不起作用。不,我的意思是target=“\u blank”
\u blank
是一个特殊的保留值,表示“一个新窗口”。请看这里:谢谢你的回复。我试过了,但结果是一样的。post响应仍在父窗口中,而不是在新窗口中。