0

I have a function showMap which opens a new window(window.open).In the new window I have a iframe googlemaps and a input with button.How can i pass the data when user clicks the button to a function in the parent window?

var popUpWindow ;
function showMap(){
     popUpWindow = window.open(index)
     popUpWindow.document.write( '<html><head><title>MAP</title>
     </head><body>
     <iframe src="https://maps.google.com/maps/embed/v1/directions?> 
     </iframe> <br> <input type="text" id="data> 
     <button type="button" onclick="opener.callParent()">
      Update</button></body></html');
}

function callParent(){
  var newValue = popUpWindow.document.getElementById('data').value;
  console.log('newVal',newValue);
}

Doing in this way i was able to get the value from child window to parent window.

Ben
  • 107
  • 1
  • 1
  • 7
  • 2
    Possible duplicate of [How to call parent window function from child window jquery?](https://stackoverflow.com/questions/25098573/how-to-call-parent-window-function-from-child-window-jquery) – Heretic Monkey Jun 07 '19 at 21:17

2 Answers2

3

Check window.opener global under that new popup

enapupe
  • 15,691
  • 3
  • 29
  • 45
  • This is a correct answer, don't know why it's down voted. Ref: https://developer.mozilla.org/en-US/docs/Web/API/Window/opener – VTr Jun 07 '19 at 21:23
0

You can use ES6 import/export.

To do that firstly export parents function then import it and use in the modal.

Another way, but dangerous one is to use global window scope to implement the method you want to call.

Prezes
  • 21
  • 3