开发者

Is it possible to stop browser redirection via Location: header with Javascript

开发者 https://www.devze.com 2023-04-11 03:27 出处:网络
I have a form processed by PHP that redirects visitors to a third-party payment system, through the use of the Location: header. The form is processed quickly, but when it comes to a payment system (P

I have a form processed by PHP that redirects visitors to a third-party payment system, through the use of the Location: header. The form is processed quickly, but when it comes to a payment system (Paypal), it takes up to 3-5 seconds to establish HTTPS connection and complete the redirection.

I'm trying to improve visitor experience by displaying a popup (JQuery Colorbox plug-in) with a "Please wait" message, like this:

$('a.submit').click(function(event) {
    event.preventDefault();
    $(this).colorbox({
        href: '#order_redirect',
        title: 'Sending data to a payment system',
        inline: true,
        fixed: true
    });
    $(this).closest('form').submit();
});

Default behavi开发者_开发技巧or of Colorbox is that you can press Esc and close the popup. I want to let the user do that and stop the redirection via a callback function (Javascript continues working for the whole time). Is it possible? It may be seconds after the browser actually receives the header.


It's hard for me to test if this stops the redirection, but should be a good start.

$('a.submit').click(function(event) {
    event.preventDefault();
    $(this).colorbox({
        href: '#order_redirect',
        title: 'Sending data to a payment system',
        inline: true,
        fixed: true,
        onClosed:function() {
            history.go(-1);
        }
    });
    $(this).closest('form').submit();
});


stop the redirection via a callback function

I do not think this is possible. The best you would be able to do would be to change the location back to the current page or use location.reload(). However, if you were submit the form via ajax, you would be able to abort it:

Abort Ajax requests using jQuery

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号