In my script I need to execute window.close();
, but it has a chance of failing (Note: See below for explain), so I want to follow up the window.close();
with a window.history.back()
, which will redirect user back a page and back to the correct web flow.
I have tried the following:
Code 1
window.close();
window.history.back();
The above worked all the time, however if I do this:
Code 2
window.close();
alert("123");
window.history.back();
The alert go before window can even close. So let me wonder if Code 1 is a safe code to use.
So I have the following question:
Is it safe to assume that in Code 1,
window.close()
will always run beforewindow.history.back()
?- and only in the case that
window.close()
is not permitted, only thenwindow.history.back()
will get called?
- and only in the case that
If not, then is it possible to detect the event of
window.close()
not being called? So I can proceed from that and execute the code I want
Note:
- The code is being run on multiple platform, and I find that in iOS10 SFSafariViewController, it does not know
window.close()
due to some reason, hence I need to callwindow.history.back()
after knowing thatwindow.close()
failed
Thanks!