468,457 Members | 1,637 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

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

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
Jul 20 '05 #1
2 17535


Halldór Ísak Gylfason wrote:
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>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
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
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Mark | last post: by
1 post views Thread by Unregistered | last post: by
2 posts views Thread by Colin McKinnon | last post: by
1 post views Thread by Ashish | last post: by
5 posts views Thread by Tim Johnson | last post: by
1 post views Thread by tony wong | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.