View Full Version : passing data from python cgi popup to parent

07-14-2004, 11:18 PM
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:-

var retVal = 0
var handle= ''
function popup() {
handle = window.open("url", "name", "attributes")
if (handle.opener == null)
handle.opener = self
if (handle.closed)

<a href="url" onClick="popup()">Click here</a>

in child:-

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.

07-14-2004, 11:28 PM
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..


07-14-2004, 11:38 PM
ummm..... i must sound terribly naive, but what's an iframe?

07-15-2004, 12:05 AM
Not naiive.... just noobie-ish! lol

Check out these links:

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

Hope that helps,

07-15-2004, 01:16 AM
thanks! but the functionality i require should be in both IE and Netscape and hence i do require javascript..

07-15-2004, 01:44 AM
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.


07-15-2004, 04:59 AM
If for some reasons you still want to use popup.
in parent:

function popup() {
var handle = window.open("url", "name", "attributes");
return false;

function doSomething(flag){
if (flag==1) { //login successful
else { //failure
<a href="url" onClick="return popup()">Click here</a>

in child:

function passval(flag) {
if (opener && !opener.closed){ //make sure opener window is still open
window.close(); //close popup
<body onload="passval(1);">

07-15-2004, 03:53 PM
thank you! it works very well!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum