0

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;
}
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
John
  • 7,500
  • 16
  • 62
  • 95

1 Answers1

1

form.target must be iframe name, not id.

Alex
  • 11,115
  • 12
  • 51
  • 64