Forum Moderators: open

Message Too Old, No Replies

Detecting frame loading

onload in frames?

         

T Suresh Babu

9:16 am on Apr 2, 2002 (gmt 0)

10+ Year Member



How to detect whether a frame is loaded or not.
The web page in that frame is not in my control.
(ie) that page is not my control.
I have to invoke a function after that page is loaded.

joshie76

3:49 pm on Apr 2, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's unlikely that you'll be able to do this as you'd be scripting across domains. If the webpage in the frame belongs to your domain then in IE you could attach an event to the window...

parent.frameName.attachEvent('onload',myEvent) 

function myEvent()
{

}

There are probably equivalent ways of attaching events in NN6 and Opera6 (anyone?)

T Suresh Babu

5:41 am on Apr 3, 2002 (gmt 0)

10+ Year Member



Joshie as you said I tried the following but IE5 says paren.newwin is not AN OBJECT.

<<<<<<<<<<<<<<

<html><br>
<head><br>
window.parent.frames["newwin"].attachEvent('onload',myEvent)
<p>function myEvent()<br>
{<br>
alert("My Event");<br>
}<br>
</script><br>
</head><br>
<FRAMESET frameborder=0 rows="100%,*"></p>
<p> <FRAME name="newwin" src="a.html"></p>
<p><br>
</FRAMESET><br>
</html>

>>>>>>>>>>>>

T Suresh Babu

5:47 am on Apr 3, 2002 (gmt 0)

10+ Year Member



Both doesn't works.

<<<<<<<<<<<<<<
<p>window.parent.frames["newwin"].attachEvent('onload',myEvent)</p>
<p>window.parent.newwin.attachEvent('onload',myEvent)
>>>>>>>>>>>

tedster

6:46 am on Apr 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I doubt that you can detect the loading of a frame when the document comes from another server. I have a similar spot on one site and I never figured out a way to do it.

So the next question would be, what did you first set out to accomplish? Can you do that another way, besides detecting the page load? If you come at the problem from "outside the box" a bit, maybe something will occur to you.

In my case, I resolved things through communicating with the web team for the page we were framing. They are European partners of my US client, so cooperation was easily worked out once we tried.

T Suresh Babu

9:45 am on Apr 3, 2002 (gmt 0)

10+ Year Member



>> resolved things through communicating with the web team for the page we were framing.

Hai tedster,

My requirement is to target middle of the page were our website info is provided by another website.

They have not provided any target name(#linkname).

I have asked them to provide a target linkname so that I can directly give the link as

<a href="page1.html#linkname">

If they refused to do so I have to scroll the page using window.scroll method.

So I decided to open that link in new window(frame page).

After loading that page I will scroll that page by appropriate offset in (px) say(window.scroll(0,330))

For doing that I should ensure that whether the page is loaded or not. After loading that page only I will be able to scroll that page. Before the loading of that appropriate page we can't scroll that page. It gives error when tried it.

I tried the following by trigerring a event which will execute after 5secs.

It worked fine (offline page).

But the download time of that page may vary depending upon the net connection, which is unpredictable since that page is a very lengthy page. So only I wanted to detect the loading of frame.

-Suresh Babu

As you said co-operation with other web team will solve this issue.

tedster

9:53 am on Apr 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the named anchor sounds like the only real solution here. With the javascript scroll method, how could you know how many pixels to scroll for every possible combination of browser, OS and font size?

Human cooperation - it's a wonderful thing. And if it's their work and they know you're framing it, they should be happy to make sure it gets displayed well, wouldn't you think?

joshie76

12:17 pm on Apr 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As I suspected (and Tedster confirms) you can't do it across domains (servers) - this is a deliberate security feature and should be the case in all browsers. However, the reason you recieved the "newwin is not AN OBJECT." error is because your inline script references the frame before you have declared it on your page - hence it doesn't yet exist.

If you change the order of your page you should find that you'll get an "Access Denied" error instead - this is the error you'd expect when you try to script across domains. It's often best to have scripts that reference document elements in the onload event for that document - preventing any curious "not AN OBJECT" errors.

Best o' luck.