0

I'm integrating a new payment method in my webpage. This method use a webredirect to send the customer to the payment page.

The redirect is made using location.href=.... command, then usually my web page is unloaded and user is sent to payment site.

I have some issue when the link is somehow opened in other window or if the customer is browsing with a phone, when the link is handled by the app link and the payment app is opened. The customer completes the payment in the second window or in the mobile app and then he focus again in my webpage, but my webpage is still because for its logic, the location.href was thrown.

I know I have somehow to handle an auto-refresh when the user comes back. How can I understand if the location.href command has unload the page or if it is just opened by an application and my page is still there?

Tobia
  • 9,165
  • 28
  • 114
  • 219

1 Answers1

0

Usually 3rd party payment redirects happen on new window & is done via window.open

Caveats: User should allow the pop-ups in the browser

It gives a better control over the new Tab / Iframe opened & establish a bi-direction communication bridge to get the status and events bi-directionally through WindowProxy like closed or check referrer.

Alternatively you can hook into window.onbeforeunload and set a flag as below

example:

window.onbeforeunload = function(){
  sessionStorage.isUnloaded = 1
}

and use the flag on window.onload to deduce if you moved away / closed / duplicate session.

NiRUS
  • 3,901
  • 2
  • 24
  • 50
  • Thanks for the answer, seems that it is a bit more complicated with applink app opening... – Tobia Oct 15 '21 at 07:41