Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Javascript,calling child window function from opener doesn't work

Javascript,calling child window function from opener doesn't work

Scheduled Pinned Locked Moved Web Development
javascripthelpquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    keniagm
    wrote on last edited by
    #1

    Hello! I'm developing a web application that opens a popup using windows.open(..). I need to call a function on the opened window using the handle returned by "window.open", but I'm always getting the error message "addWindow.getMaskElements is not a function", as if it couldn't access the function declared on child window. This is the behavior in both IE and FF. My code looks like this: function AddEmail(target,category) {      if(addWindow == null)      {           currentCategory = category;           var left = getDialogPos(400,220)[0];           var top =   getDialogPos(400,220)[1];           addWindow = window.open("adicionar_email.htm",null,"height=220px, width=400px, status=no, resizable=no");           addWindow.moveTo(left,top);           addWindow.getMaskElements ();      } } I've googled and read from different reliable sources and apparently this is supposed to work, however it doesn't. One more thing, the functions in child window are declared in a separate .js file that is included in the adicionar_email.htm file. Does this make a difference? It shouldn't.. So, if anyone has ran into a similar problem, or has any idea of what I'm doing wrong, please, reply to this message. Thanks in advance.

    Kenia

    D 1 Reply Last reply
    0
    • K keniagm

      Hello! I'm developing a web application that opens a popup using windows.open(..). I need to call a function on the opened window using the handle returned by "window.open", but I'm always getting the error message "addWindow.getMaskElements is not a function", as if it couldn't access the function declared on child window. This is the behavior in both IE and FF. My code looks like this: function AddEmail(target,category) {      if(addWindow == null)      {           currentCategory = category;           var left = getDialogPos(400,220)[0];           var top =   getDialogPos(400,220)[1];           addWindow = window.open("adicionar_email.htm",null,"height=220px, width=400px, status=no, resizable=no");           addWindow.moveTo(left,top);           addWindow.getMaskElements ();      } } I've googled and read from different reliable sources and apparently this is supposed to work, however it doesn't. One more thing, the functions in child window are declared in a separate .js file that is included in the adicionar_email.htm file. Does this make a difference? It shouldn't.. So, if anyone has ran into a similar problem, or has any idea of what I'm doing wrong, please, reply to this message. Thanks in advance.

      Kenia

      D Offline
      D Offline
      daveyerwin
      wrote on last edited by
      #2

      Here is a good guess. The Function addWindow.getMaskElements (); is being called before it is ready in addWindow. You could try this ... setTimeout("addWindow.getMaskElements()",2000); That will wait two seconds before calling addWindow.getMaskElements().

      modified on Friday, January 22, 2010 10:39 AM

      K 1 Reply Last reply
      0
      • D daveyerwin

        Here is a good guess. The Function addWindow.getMaskElements (); is being called before it is ready in addWindow. You could try this ... setTimeout("addWindow.getMaskElements()",2000); That will wait two seconds before calling addWindow.getMaskElements().

        modified on Friday, January 22, 2010 10:39 AM

        K Offline
        K Offline
        keniagm
        wrote on last edited by
        #3

        Thanks! that was exactly the problem. I did what you suggested and it works perfectly now, thanks again

        Kenia

        D 1 Reply Last reply
        0
        • K keniagm

          Thanks! that was exactly the problem. I did what you suggested and it works perfectly now, thanks again

          Kenia

          D Offline
          D Offline
          daveyerwin
          wrote on last edited by
          #4

          Kewl! Uh, there is a better solution. I sugessted the setTimeout just to confirm what the problem was. The problem with the two second delay is you cant be sure it will be ready. You could call addWindow.getMaskElements (); repetively by catching the error and setting time out again. Or you could try this, in the separate .js file that is included in the adicionar_email.htm add this line ... body.onload = "window.opener.iMready()"; in the parent page put this... function iMready(){ addWindow.getMaskElements (); } if there is already an onload function (it might be window.onload body.onload or onload people do it different ways) declared in the .js, you cant have another so add this line to the function onload points to... window.opener.iMready();

          K 1 Reply Last reply
          0
          • D daveyerwin

            Kewl! Uh, there is a better solution. I sugessted the setTimeout just to confirm what the problem was. The problem with the two second delay is you cant be sure it will be ready. You could call addWindow.getMaskElements (); repetively by catching the error and setting time out again. Or you could try this, in the separate .js file that is included in the adicionar_email.htm add this line ... body.onload = "window.opener.iMready()"; in the parent page put this... function iMready(){ addWindow.getMaskElements (); } if there is already an onload function (it might be window.onload body.onload or onload people do it different ways) declared in the .js, you cant have another so add this line to the function onload points to... window.opener.iMready();

            K Offline
            K Offline
            keniagm
            wrote on last edited by
            #5

            In fact, that about calling repetively the addWindow.getMaskElements(); is what i did, because i didn't want to modify the function already attached to the onload event of the document. Thanks for your time!

            Kenia

            D 1 Reply Last reply
            0
            • K keniagm

              In fact, that about calling repetively the addWindow.getMaskElements(); is what i did, because i didn't want to modify the function already attached to the onload event of the document. Thanks for your time!

              Kenia

              D Offline
              D Offline
              daveyerwin
              wrote on last edited by
              #6

              I'm happy I could help.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups