|
|
|
date: Sun, 9 Oct 2005 02:02:04 -0700,
group: microsoft.public.inetsdk.programming.scripting.jscript
back
Re: popup jscript problem?
"nick" wrote in message
news:A6DB6749-C451-48FF-9F06-21D327CE3D76@microsoft.com
> I have the following code to popup a window and set an img's src
> property:
> var winref = window.open("../popup.htm", "popup",
> "width=600,height=500,toolbar=0,resizable=0")
> if (winref && isMethodType(typeof winref.focus))
> {
> winref.document.getElementById("mainPic").src = mainPic.src
>
> However, I found that sometime it works, but sometime it doesn't work
> with error: "Error: 'document.getElementById(...)' is null or not an
> object" on the line: winref.document.getElementById("mainPic").src =
> mainPic.src
window.open creates a new browser window and initiates navigation, then
returns. The navigation proceeds asynchronously. So you have a race
condition: sometimes the popup page finishes loading by the time you
call getElementById, but other times it is still loading, and the
mainPic element has not yet been created.
You need to wait until the popup window fires onload event before you
can access its elements reliably.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
date: Sun, 9 Oct 2005 08:42:56 -0400
author: Igor Tandetnik
|
|