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
  • 959,406
  • 173
  • 1,780
  • 1,769
John
  • 6,900
  • 15
  • 60
  • 92

1 Answers1

1

form.target must be iframe name, not id.

Pinal
  • 10,775
  • 12
  • 49
  • 62