IE问题:使用JavaScript将表单提交给iframe [英] IE Issue: Submitting form to an iframe using javascript
问题描述
var iframe = document.createElement('iframe );
iframe.setAttribute('name','frame_x');
然而,当我尝试使用新创建的iframe作为目标提交表单时,IE打开了一个新窗口,而不是使用iframe。
form.setAttribute('target','frame_x');
form.submit();
这完美适用于Firefox。此外,iframe也会被创建,但不会被使用。 你已经打过 Internet Explorer中的错误 。
CAN NOT 使用标准DOM方法 在IE中设置 ANY 元素的名称属性>
.setAttribute('name',value);
在使用IE8标准模式运行的版本8之前),此方法将无法设置名称属性。 您需要使用以下其中一项:
// A(任何浏览器)
var iframe = document.createElement('iframe');
iframe.name ='frame_x';
// B(仅在IE中)
var iframe = document.createElement('< iframe name =frame_x/>');
// C(使用修复bug的JS库(例如jQuery))
var iframe = $('< iframe name =frame_x>< / iframe> );
// D(使用jQuery在现有元素上设置属性)
$('iframe:first')。attr('name','frame_x');
I was trying to create an iframe element using javascript, like so:
var iframe = document.createElement('iframe');
iframe.setAttribute('name', 'frame_x');
However, when I tried submitting a form using the newly-created iframe as target, IE opens up a new window, instead of using the iframe.
form.setAttribute('target', 'frame_x');
form.submit();
This works perfectly in Firefox. Also, the iframe gets created, but is not used.
You've hit a bug in Internet Explorer.
You CAN NOT set the name attribute of ANY element in IE using the standard DOM Method .setAttribute('name', value);
In IE (before version 8 running in IE8 standards mode) this method will not work to set the name attribute.
You need to use one of the following:
//A (any browser)
var iframe = document.createElement('iframe');
iframe.name = 'frame_x';
//B (only in IE)
var iframe = document.createElement('<iframe name="frame_x"/>');
//C (use a JS library that fixes the bug (e.g. jQuery))
var iframe = $('<iframe name="frame_x"></iframe>');
//D (using jQuery to set the attribute on an existing element)
$('iframe:first').attr('name','frame_x');
这篇关于IE问题:使用JavaScript将表单提交给iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!