6

Hi I have a parent window, lets saz M, on clicking a button in M, a popup window is opened. When some option is selected in the popup and the OK button is clicked, the popup should close and in the main window a message should be displayed. Is this possible through javascript?

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • possible duplicate of [Popup window to return data to parent on close](http://stackoverflow.com/questions/9276086/popup-window-to-return-data-to-parent-on-close) and many others – JJJ Oct 13 '13 at 11:05
  • yes, please look at [this link](http://www.w3schools.com/js/js_popup.asp). (I know w3schools sucks but on this subject they are relatively ok) – Jean-Paul Oct 13 '13 at 11:05
  • I made a mistake, not an alert message, but rather a option must get selected. Like a combo box on the main page should get set based on the value selected in the popup. – Royce Lanson Pinto Oct 13 '13 at 11:08

1 Answers1

13

yes, it's possible.

close a popup with window.close()

communicate with parent window with window.opener.postMessage() (window.opener is the parent window object, you can even call a direct named function within it for example window.opener.funcName())

next time please look for existing solution before you ask for one, there are plenty of those.

good luck

geevee
  • 5,411
  • 5
  • 30
  • 48
  • But `window.opener` does not exist in IE, is there a workaround? – Reiner Nov 02 '17 at 20:21
  • @Reiner, see answer here: https://stackoverflow.com/questions/23562044/window-opener-is-undefined-on-internet-explorer – geevee Nov 20 '17 at 09:49
  • and you can listen to the event in the parent window using `window.addEventListener('message', ()=>{});` see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#the_dispatched_event – Dimitry K Feb 18 '21 at 16:34