Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popup window to return data to parent on close

I've got a popup window opened using window.open(). What I want now is for a user to be able to click one of 2 links within this new window: "Allow" or "Don't Allow".

When a user clicks one of those links the 'popup' window should close, and return either "allow" or "don't allow" or something along those lines, true/false would do, to the parent window.

Is it possible? If so, how?

Code:

var authWindow = window.open('auth.php', 'authWindow', 'options...'); 

Then just 2 anchors inside auth.php?

like image 273
Joey Emery Avatar asked Feb 14 '12 11:02

Joey Emery


People also ask

How do I pass data from popup to parent window?

parent. document. getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.

How do I close the child window from the parent window?

A child window opens as separate window as a tab. Go back to the parent and click “Close child” and the child window closes. Viola!

How do I get a return value from a Windows Open?

Typically the onclick event on the "Yes" or "Ok" button in the modal dialog looks like this: window. returnValue = true; window. close();


1 Answers

In the calling (parent) window add such JS code:

function HandlePopupResult(result) {     alert("result of popup is: " + result); } 

In the child window code add this:

function CloseMySelf(sender) {     try {         window.opener.HandlePopupResult(sender.getAttribute("result"));     }     catch (err) {}     window.close();     return false; } 

And have such links to close the popup:

<a href="#" result="allow" onclick="return CloseMySelf(this);">Allow</a> <a href="#" result="disallow" onclick="return CloseMySelf(this);">Don't Allow</a> 
like image 133
Shadow Wizard Hates Omicron Avatar answered Sep 18 '22 22:09

Shadow Wizard Hates Omicron