By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,348 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,348 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a


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

P: n/a
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.