Aaron Gibralter
Aaron Gibralter

Reputation: 4853

<FORM> posting to <IFRAME> causes pop up window in IE7 only

I'm construction a iframe and form with jQuery as such:

iframe = $("<iframe>", {name : "foo"});
form = $("<form>", {
  target : $iframe.attr("name"),
  action : "/foobar",
  method : "POST"
}).append($("<input>", {
  type  : "submit",
  name  : "amifully",
  value : "dressed"
}).hide());
$("body").append(iframe).append(form);
form.submit();

For some reason, in Chrome/Safari/Firefox/IE8+ it works great but in IE7 it opens the form in a pop up window.

Anyone have any idea what's going on?

Upvotes: 2

Views: 2392

Answers (1)

Aaron Gibralter
Aaron Gibralter

Reputation: 4853

Ahhh! I figured it out! Basically, IE7 freaks out when you try to add name attributes to elements with jQuery... you have to create the name in the raw string as such:

iframe = $("<iframe name=\"foo\">");

It was such a subtle thing! Hope this helps prevent someone else from spending 5 hours scouring the internet for an answer.

Upvotes: 6

Related Questions