Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

how to tell if a popup has fully loaded

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Is it possible to tell from a parent window if a popup window has fully loaded?

I'm running some javascript on a popup window from a parent window and it can only be done once the popup has fully loaded. Is this possible? I can set a timer, but that does not guarantee that the popup fill fully load before the timer expires, unless I set the timer to a large value, but that is awkward for the user.

How is a situation like this typically handled?

Thanks!
Homer
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put an onload handler on the popup window which can call a function on the parent telling it that it is loaded

for example you can just do

<body onload="window.opener.YourFunction()">

If that does not work because you can not touch the code of the popup since your partner is anal about people changing their code, you can put a try catch statement in the opener and call it every X milliseconds and when it sees the element, it knows the page is loaded.

Eric
 
Homer Hill
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eric.

I would need to use the second method you described as I can't touch the code in the popup window.

Just to clarify, are you saying that I should do something like this:

popup = window.open(...);
loaded = false;
while (loaded == false) {
try {
if (popup) { //will this line return true ONLY when the popup has loaded?
loaded = true;
}
<execute javascript on popup>
} catch (e) {
}
}

thnx
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A little confused. Does JS also support struct?

Thanks,
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I came up with:



A while loop would freeze the browser.

Hope it helps...
Eric
[ June 07, 2005: Message edited by: Eric Pascarello ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Sophie Cameron:
A little confused. Does JS also support struct?

Thanks,




Yes there is a try catch
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic