为什么Internet Explorer在新窗口中打开表单,而不是在动态插入的iframe中? [英] Why does Internet Explorer open form submission in a new window and not in a dynamically inserted iframe?

查看:105
本文介绍了为什么Internet Explorer在新窗口中打开表单,而不是在动态插入的iframe中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将表单发布到隐藏的动态插入iframe,但在Internet Explorer中,表单提交将在新窗口中打开。  var iframe = document.createElement('iframe'); 
iframe.name ='hidden_​​iframe';
iframe.className ='NotVisible';
iframe.id ='hidden_​​iframe';
document.body.appendChild(iframe);

var my_form = document.getElementById('my_form');
my_form.target ='hidden_​​iframe';

这可以在Firefox中使用,但不适用于Internet Explorer。

解决方案

显然,您需要在对createElement的调用中包含该名称。这在IE中起作用,并在符合标准的浏览器中引发异常。我们得到:

  var iframe; 
try {
iframe = document.createElement('< iframe name =hidden_​​iframe>');
} catch(ex){
iframe = document.createElement('iframe');
iframe.name ='hidden_​​iframe';
}

iframe.className ='NotVisible';
iframe.id ='hidden_​​iframe';
document.body.appendChild(iframe);

var my_form = document.getElementById('my_form');
my_form.target ='hidden_​​iframe';


I am trying to get post a form to a hidden, dynamically inserted iframe, but in Internet Explorer the form submission opens in a new window.

var iframe = document.createElement('iframe');
iframe.name = 'hidden_iframe';
iframe.className = 'NotVisible';
iframe.id = 'hidden_iframe';
document.body.appendChild(iframe);

var my_form = document.getElementById('my_form');
my_form.target = 'hidden_iframe';

This works in Firefox but not Internet Explorer.

解决方案

Apparently you need to include the name in the call to createElement. This works in IE and causes an exception in standards compliant browsers. We get:

var iframe;
try {
    iframe = document.createElement('<iframe name="hidden_iframe">');
} catch (ex) {
    iframe = document.createElement('iframe');
    iframe.name='hidden_iframe';
}

iframe.className = 'NotVisible';
iframe.id = 'hidden_iframe';
document.body.appendChild(iframe);

var my_form = document.getElementById('my_form');
my_form.target = 'hidden_iframe';

这篇关于为什么Internet Explorer在新窗口中打开表单,而不是在动态插入的iframe中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆