detecting when a frame has loaded the result of a form submit

  • Thread starter Halldór Ísak Gylfason
  • Start date
H

Halldór Ísak Gylfason

In my application I have an iframe that is empty (and not visible)
initially, however when a user presses a button a form is
programmatically submitted and the target is set to the IFrame.

I want to detect when the frame has been loaded with the result of the
form submit.

Of course I have tried some event handlers like onload, onactivate,
onreadystatechange, but they do not work in this example. They only
seem to work, when the "SRC" attribute of the "IFrame" is set, e.g.
not when the IFrame is set as the target of the form.

Any ideas on how to do this?

Regards, Halldor
 
M

Martin Honnen

Halldór Ísak Gylfason said:
In my application I have an iframe that is empty (and not visible)
initially, however when a user presses a button a form is
programmatically submitted and the target is set to the IFrame.

I want to detect when the frame has been loaded with the result of the
form submit.

Of course I have tried some event handlers like onload, onactivate,
onreadystatechange, but they do not work in this example. They only
seem to work, when the "SRC" attribute of the "IFrame" is set, e.g.
not when the IFrame is set as the target of the form.

Any ideas on how to do this?

With Netscape 7 and IE6 the following intially doesn't show the iframe
and then shows it when the form is submitted

<html>
<head>
<title>iframe onload handler</title>
</head>
<body>
<form action="jsInterpreter.html"
target="frameName">
<p>
<input type="text" name="GOD" value="Kibo">
<input type="submit">
</p>
</form>
<p>
<iframe name="frameName" style="display: none;"
onload="if (typeof this.loadCount == 'undefined') {
this.loadCount = 0;
}
this.loadCount++;
if (this.loadCount > 1) {
this.style.display = '';
}"></iframe>
</p>
</body>
</html>

Doesn't work with Opera 7 as that doesn't support
<iframe onload
thus if you need to have it work cross browser you are probably better
off to use the onload handler of the page to which the form is submitted.
However when I try the following as the containing page

<html>
<head>
<title>iframe onload handler</title>
</head>
<body>
<form action="test2003091501.html"
target="frameName">
<p>
<input type="text" name="GOD" value="Kibo">
<input type="submit">
</p>
</form>
<p>
<iframe name="frameName" id="frameName" style="display: none;"></iframe>
</p>
</body>
</html>

and the following as the frame page

<html>
<head>
<title>iframe load test</title>
<script type="text/javascript">
function showFrame () {
if (window != parent) {
if (document.getElementById) {
var iframe = parent.document.getElementById(this.name);
iframe.style.display = '';
}
}
}
</script>
</head>
<body onload="showFrame();">
<p>
iframe load test
</p>
</body>
</html>

then it still doesn't work with Opera 7 as that opens a new window to
submit the form to, probably as the iframe with display: none is not
considered a form target.
When I change the containing page to

<html>
<head>
<title>iframe onload handler</title>
</head>
<body>
<form action="test2003091501.html"
target="frameName">
<p>
<input type="text" name="GOD" value="Kibo">
<input type="submit">
</p>
</form>
<p>
<iframe name="frameName" id="frameName"
style="visibility: hidden;"></iframe>
</p>
</body>
</html>

and the frame to

<html>
<head>
<title>iframe load test</title>
<script type="text/javascript">
function showFrame () {
if (window != parent) {
if (document.getElementById) {
var iframe = parent.document.getElementById(this.name);
iframe.style.visibility = 'visible';
}
}
}
</script>
</head>
<body onload="showFrame();">
<p>
iframe load test
</p>
</body>
</html>
 
A

asdf asdf

The target of the form can return html containing some javascript that
notifies your app of success or failure (provided they are in the same
domain)

Hope that helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top