How do you prevent a user from cancelling a page redirect?

I have a line of code:

location.href = 'payments/basic.php';

It works fine, but a user can simply press the Esc key to cancel the operation. I tried to use an event listener to prevent the Esc key from being pressed, but it only works while the user is on the initial page. As soon as they are being redirected, it stops working and they can quickly press the Esc key or the big X beside the address bar in their browser to cancel the redirect.

Is there a way I can completely prevent that?

Edit: The reason I want to do this is that upon login, they are automatically sent to the index page. I have a flag in my DB which checks if a user has made payment. And then on the index page, I have a little script that queries the DB to check if the flag is true or false. If it’s false, they are immediately notified that they are being redirected to make their payment. If at this point of redirection, they cancel, they will be able to remain on the Index page without payment.

Answer

Why not do it the other way around? Default to the payment page, if payment is already made, then redirect to index. lol.

Leave a Reply

Your email address will not be published. Required fields are marked *