Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
inet
active_desktop
active_scrptng
asp.components
asp.db
asp.general
comctl32
comp.packaging
components.dev
dbweb
dhtml_editing
docobjects
html_authoring
html_objmodel
iis
iis.ftp
iis.security
iis.smtp_nntp
indexserver
misc
mshtml_hosting
scripting.jscript
scripting.vbscript
sdk_setup
shell_objmodel
urlmonikers
webbrowser_ctl
wininet
  
 
date: Sun, 9 Oct 2005 02:02:04 -0700,    group: microsoft.public.inetsdk.programming.scripting.jscript        back       


popup jscript problem?   
I have the following code to popup a window and set an img's src property:

    <script type="text/javascript">
      function isMethodType(s)
      {
        return (s == "function" || s == "object");
      } 
      var mainPic = document.getElementById("mainPic")
      mainPic.onclick = function () 
      { 
        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
          winref.focus();
        } 
      }
  </script>
</body>

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

Did I missed anystep? 

Thanks,
date: Sun, 9 Oct 2005 02:02:04 -0700   author:   nick

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

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us