Wait for loading in a frame

C

ch.funke

Hello,

with:

window.setTimeout("document.myform.submit();",500);

I shoot a formular which posts some data. The target is an iframe. Now
I would like to "wait" until the iframe is read with page loading/
processing the data, then immediately do some other things, let's say
show an alert.

At the moment I do with:

window.setTimeout("alert('hi')",8000);

knowing that also on slow connections the iframe is ready after 8
seconds. But I want to optimize this to fire the alert directly when
the frame is "ready". I have NO influence of the content of the page
which is loaded into the iframe and I can't change something on that.

What I need is a check if the iframe-status is "ready" or "200" or
something like that...
Thanks for any help in advance.

Kind Regards,
Christian Funke
 
B

Botan Guner

Hi,

You can use window.addEventListener for Firefox, Mozilla, Netscape and
window.attachEvent for Microsoft Internet Explorer. Idea is that put a
script in your page that load's in the iframe like below;

<script type="text/javascript">
var browser=(navigator.appName=="Netscape")?true:false;// i have
checked only ie and mozilla browsers
var f = function() {
parent.someForm.submit();
}
if(browser) {//mozilla, firefox, netscape
window.addEventListener('load',f,false);
} else {//ie
window.attachEvent("onload",f);
}
</script>

This will submit the parent form when all the content in the iframe's
page loaded. I hope this helps...
 
T

Thomas 'PointedEars' Lahn

with:

window.setTimeout("document.myform.submit();",500);

I shoot

.... "myself happily in the foot". We have resolved this yesterday already.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Botan said:
You can use window.addEventListener for Firefox, Mozilla, Netscape and
window.attachEvent for Microsoft Internet Explorer. Idea is that put a
script in your page that load's in the iframe like below;

<script type="text/javascript">
var browser=(navigator.appName=="Netscape")?true:false;// i have
checked only ie and mozilla browsers

You have not. You have tested IE and Netscapes.
var f = function() {
parent.someForm.submit();
}

Ever heard of a `function' declaration?
if(browser) {//mozilla, firefox, netscape
window.addEventListener('load',f,false);
} else {//ie
window.attachEvent("onload",f);
}
</script>

It has been a while since I have read such a load of junk.

Before posting, one should consult the FAQ of this newsgroup:

http://jibbering.com/faq/
http://pointedears.de/scripts/test/whatami


PointedEars
 
C

ch.funke

Well, it worked after some modifications, but the idea with
EventHandler was good.
This is how I do now (using prototype libary).


function test()
{
if (window.opera)
{
window.location.href=finalurl;
}
else
{
top.location.href=finalurl;
}
}

function addEvent(obj, eventType, fn, useCaption)
{
if (obj.addEventListener) {
obj.addEventListener(eventType, fn, useCaption);
return true;
} else if (obj.attachEvent) {
var retVal = obj.attachEvent("on"+eventType, fn);
return retVal;
} else {
return false;
}
}

function removeEvent( obj, type, fn )
{
if (obj.removeEventListener) {
obj.removeEventListener( type, fn, false );
} else if (obj.detachEvent) {
obj.detachEvent( "on"+type, fn );
obj[type+fn] = null;
obj["e"+type+fn] = null;
}
}
addEvent($('myiframe'), 'load', test, false);
document.myform.submit() // <=== send form into myiframe
 
T

Thomas 'PointedEars' Lahn

Well, it worked

And what would `it' be? Have you still not learned how to quote?
after some modifications, but the idea with EventHandler was good.

You mean event listeners.
This is how I do now (using prototype libary).

I feared that you might. Including 27K of code for one line of code
that is not even needed. OMG.
function test()
{
if (window.opera)
{
window.location.href=finalurl;
}
else
{
top.location.href=finalurl;
}
}

That is just plain utter nonsense.
function addEvent(obj, eventType, fn, useCaption)

It's capture (here: to catch, to take), not caption (title).
{
if (obj.addEventListener) {

That is hardly a sufficient feature test. Search for `isMethodType' instead.
obj.addEventListener(eventType, fn, useCaption);
return true;
} else if (obj.attachEvent) {
var retVal = obj.attachEvent("on"+eventType, fn);
return retVal;
} else {
return false;
}
}

Search for `_addEventListener' instead.
function removeEvent( obj, type, fn )
{
if (obj.removeEventListener) {
obj.removeEventListener( type, fn, false );

This will fail to remove event listeners for captured events.
} else if (obj.detachEvent) {
obj.detachEvent( "on"+type, fn );
obj[type+fn] = null;
obj["e"+type+fn] = null;

What useful thing would those last two lines do? None.

My dhtml.js will soon also feature a less error-prone method for that:

function _removeEventListener(o, sEvent, fListener, bUseCapture)
{
var result = false, sHandler = "on" + sEvent;

if (o && sEvent && isMethodType(typeof fListener) && fListener)
{
if (isMethodType(typeof o.removeEventListener) && o.removeEventListener)
{
o.removeEventListener(sEvent, fListener, !!bUseCapture);
result = true;
}
else
{
if (isMethodType(typeof o.detachEvent) && o.detachEvent)
{
result = o.detachEvent(sHandler, fListener);
}

if (!result)
{
o[sHandler] = null;
result = (o[sHandler] == null);
}
}
}

return result;
}
addEvent($('myiframe'), 'load', test, false);

addEvent(document.frames["myiframe"], ...);

or
document.myform.submit() // <=== send form into myiframe

in the iframed document:

<!-- add feature test here -->
<body onload="window.parent.document.forms['myform'].submit();">
...
</body>


HTH & HAND

PointedEars
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top