Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Internet Explorer open form submission in a new window and not in a dynamically inserted 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.

like image 453
lambacck Avatar asked May 17 '09 22:05

lambacck


1 Answers

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';
like image 195
lambacck Avatar answered Nov 19 '22 22:11

lambacck