Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE7 Bug - Set iframe onload before submit 1

Status
Not open for further replies.

Kirsle

Programmer
Jan 21, 2006
1,179
US
I've stumbled upon a rather annoying bug in Internet Explorer 7.

I have a form on one page that submits into an iframe on the same page. Just before allowing the form to submit, it needs to set an onLoad handler on the iframe, so that a callback can be called when the page is loaded -- to give the user confirmation that their form was submitted.

I've isolated the IE7 bug by putting together a really simple example:

page.html
Code:
<html>
<head>
<title>iframe bug test</title>
</head>
<body>

<fieldset>
<legend>The IFrame</legend>
<iframe name="myframe" id="if_myframe" src="" width="200" height="200"></iframe>
</fieldset><p>

<form name="myForm" onSubmit="return doSubmit()" action="submitto.html" target="myframe" method="post">
<fieldset>
<legend>The Form</legend>

   Name:
   <input type="text" size="20" name="name" id="name" value="Rumpelstiltskin"><br>
   Quest:
   <input type="text" size="20" name="quest" id="quest" value="search for the holy grail"><br>
   <input type="submit" value="Submit Form">
</fieldset>
</form>

<fieldset>
<legend>wtf?</legend>
Internet Explorer 7 has a bug in trying to bind an onload handler to this iframe during the submission
of the form.<p>

Expected behavior: submit the form, see "Form submission page loaded" in the iframe, get a popup
saying "Submission OK!" (if any fields are missing, just get a popup about those and no submission).<p>

IE7's behavior: the iframe shows "Form submission page loaded", but no popup saying "Submission OK!"<p>

View the source to see how it works. The page receiving the submission is just "submitto.html", a
regular html page. No further dependencies involved.
</fieldset>

<script>
function doSubmit() {
   if (document.getElementById("name").value.length == 0) {
      window.alert("enter a name");
      return false;
   }
   if (document.getElementById("quest").value.length == 0) {
      window.alert("enter a quest");
      return false;
   }

   // Set the onLoad handler for the iframe
   document.getElementById("if_myframe").onload = function() {
      handleSubmitted();
   };

   // Submit the form.
   document.myForm.submit();

   return false;
}

function handleSubmitted() {
   window.alert("Submission OK!");
}
</script>

</body>
</html>

submitto.html
Code:
<h1>Form submission page loaded</h1>

This can currently be seen at:
I know that using iframes in this way is called the "poor man's ajax", however, for my purposes, the form contains a file upload field and that can't be handled in ajax. It would also be very inconvenient to do a "traditional" form submit where an entire new page is loaded, because this form pops up in a JavaScript "window" on the page the user is currently viewing so they can submit bug reports.

Any ideas for a workaround?

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Nice! Thanks for the link.

I ended up just modifying the CGI that loads inside the iframe so it calls "parent.submitCallback()" when it loads, but the link you sent will come in handy if I run into a similar issue again in the future (or if the QA guys don't like me mixing javascript in with perl and want me to try something else!)

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top