Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passing data from python cgi popup to parent

    Hi all,
    I'm trying to implement a user authentication for a python s/w by use of javascript. When user clicks on a link(python cgi), a window pops-up asking for username and calls 2 diff cgi/py files to validate & log the user details.

    What I need to do is after it succeeds, is to pass a variable(success/failure) back to parent at the same time closing pop-up so parent can take action depending on variable value.
    the pop-up works, but passing variable by opener.retVal doesn't.

    in parent:-
    Code:
    var retVal = 0
    var handle= ''
    function popup() {
      handle = window.open("url", "name", "attributes")
      if (handle.opener == null) 
         handle.opener = self
      if (handle.closed)
         window.alert(retVal)
    }
    
    <a href="url" onClick="popup()">Click here</a>
    in child:-
    Code:
    function passval() {
      opener.retVal = 1
    }
    
    <body onLoad="passval();self.close();">
    The problem is as soon as popup window opens, the handle.closed statement is executed & fails because child is still open. How can I avoid this? How will it wait till child is closed?

    I have been looking at FAQ's, & sites since morning but no answer. Sorry if my question seems too simple, but I'm hoping someone will reply. Thanks in advance.

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why do you use a popup window as opposed to an iFrame? It's cleaner and it works better and you don't need to worry about windows opening and the like..

    Sadiq.

  • #3
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ummm..... i must sound terribly naive, but what's an iframe?

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not naiive.... just noobie-ish! lol

    Check out these links:
    http://www.webclass.ru/eng/Tutorials...RAME_tags.html
    http://www.htmlgoodies.com/tutors/inlineframes.html

    To make it hidden:
    <iframe style="visibility:hidden"></iframe>

    Hope that helps,
    Sadiq.

  • #5
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks! but the functionality i require should be in both IE and Netscape and hence i do require javascript..

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh I know, and I'm not saying not to use Javascript, I'm saying don't use the popup window. Use the iFrame instead of the popup window.

    This way you give the iFrame a name, and you can refer to the iFrame like you would a regular frame. Since the iFrame is embedded into the webpage, within the iFrame you can refer to the webpage using parent.

    I just thing it looks more professional than having a window popping up and disappearing for no reason, and keep in mind that this popup window may not open due to popup blockers.

    Sadiq.

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,960
    Thanks
    0
    Thanked 236 Times in 233 Posts
    If for some reasons you still want to use popup.
    in parent:
    Code:
    function popup() {
      var handle = window.open("url", "name", "attributes");
      handle.focus();
      return false;
    }
    
    function doSomething(flag){
      if (flag==1) {  //login successful
         alert("OK");
      }
      else { //failure
         alert("Failed.");
      }
    }
    ...
    <a href="url" onClick="return popup()">Click here</a>
    in child:
    Code:
    function passval(flag) {
      if (opener && !opener.closed){ //make sure opener window is still open
        opener.doSomething(flag);
        opener.focus();
      }
      window.close(); //close popup
    }
    ...
    <body onload="passval(1);">

  • #8
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you! it works very well!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •