0

Hello i am using the react js and i am open a new window using this method.

var newWindow = window.open(
  this.state.url,
  'myWindow',
  "location=yes,width=600,height=600"
)

Using this method a new window is open and a redirection url is open and getting the response in new window i just want to close new window pop up after getting response. the redirection link is actually a api link in which i am sending the response.

Help me get out of this. Thanks

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
Jony Mittal
  • 151
  • 6
  • 23
  • Is it possible to instead make the request in the current scope, i.e. with a `fetch` or using `axios`? Or are you trying to close the window automatically after some specified interaction from a user? – Drew Reese Jan 03 '20 at 06:42
  • When getting response from api you must be doing something on that data, so at that time you can write the logic for close. – Saima Haji Jan 03 '20 at 06:43

3 Answers3

0

you can get the event loadstop of newwindow and then close it.

  • what is the use of load stop – Jony Mittal Jan 03 '20 at 07:34
  • in new window the api is hitting and url is changed how can i cloase it whilw i am not getting any response in parent window – Jony Mittal Jan 03 '20 at 07:35
  • Try this, Assuming you have no same-origin problems, that should now work. var newWindow = window.open( "https://ionicframework.com/docs/v3/native/http/", 'myWindow', "location=yes,width=600,height=600" );newWindow.addEventListener('loadstop', function(event){ newWindow.close(); }); – shishir yadav Jan 09 '20 at 07:23
0

I think this approach will solve your Issue. At leas if you open the new Window interaktiv. Automatically close browser/tab without opening it by javascript

Snippet from the other post which should be part of the response (dont know if possible in your case).

<script language="JavaScript" type="text/javascript">
    function winClose() {
       window.setTimeout("window.close();",2000)
    }
</script>
TheShadow
  • 581
  • 4
  • 10
0

You have newWindow reference to your window pop up. Now you can listen onload method which gets fired once your window is fully loaded with content and dom is generated. Refer here. DO your stuff inside this funciton.

newWindow.onload = function() {
  // do your stuff here
  newWindow.close()
};
vipul patel
  • 668
  • 4
  • 7
  • 3
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – leopal Jan 03 '20 at 07:32