Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  22] [ 2]  / answers: 1 / hits: 31786  / 15 Years ago, tue, february 2, 2010, 12:00:00

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.


More From » forms

 Answers
1

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');

[#97688] Friday, January 29, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isaacvalentinn

Total Points: 325
Total Questions: 120
Total Answers: 131

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
isaacvalentinn questions
Mon, Jan 18, 21, 00:00, 3 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Wed, Sep 23, 20, 00:00, 4 Years ago
;