John
John

Reputation: 7910

IE9 opens new tab on form submit ( form has target attibute, pointed to dynamically created iframe )

I have a javascript function which dynamically creates an iframe for a form, so the form is sent to iframe. The code works in Chrome, Opera and Firefox, but IE opens new tab when I submit the form.

how to fix this issue?

HTML:

<form id="form1" name="form1" action="/post.php" method="post">
  <input type="text" name="foo" value="bar">
  <button type="submit" name="send">Send</button>
</form>

Javascript (runs on page load):

var form = document.getElementById("form1");
if(!form.target) {
  var frame = document.createElement("iframe");
  frame.name = "frame" + Math.random();
  frame.id = frame.name;

  document.body.appendChild(frame);

  form.target = frame.id;
}

Upvotes: 0

Views: 1451

Answers (1)

Alex
Alex

Reputation: 11245

form.target must be iframe name, not id.

Upvotes: 1

Related Questions