Display Alert On Browser Tab Close

Hello Friends,

I have a code written in Yii-php which will works in following way…

When user click on upgrade package option. A curl request will run and perform task on remote server (REST API CALL).

After success the payment will be done also on a remote server (Using Recurly API)

After payment success the records will be saved to database.


Now, My logic fails when user close the browser during this process.

I want to restrict the user or remind the user that "Your transaction is in process. Please wait".

Please suggest me a solution…

What about a javascript that detects the event "onbeforeunload" or "unload" on the windows object?

See examples here:


This event also works when I submit the form to start the transaction. :( :(