[英]Return to different page when clicking back button in browser after payment
I heard that this is bad idea but I'll try to explain what I want to achieve: 我听说这是个坏主意,但我将尝试解释我要实现的目标:
On my site a user fills some information and then goes to another service which handles user payment. 在我的网站上,用户填写了一些信息,然后转到另一个处理用户付款的服务。 So after the user pays using credit card he got redirected to special $successUrl
again to my site where he sees successful payment message. 因此,在用户使用信用卡付款后,他又被重定向到特殊的$successUrl
再次访问了我的网站,在该网站上他看到了成功的付款消息。 My boss wants that after payment if the user clicks back button (being on success page) instead of going to payment service again he have to be redirected to main page. 我的老板希望付款后,如果用户单击“后退”按钮(位于成功页面上)而不是再次进入付款服务,则必须将他重定向到主页。
How to achieve that? 如何实现呢? I can't thought of a good solution. 我想不出一个好的解决方案。 Only something like catch back button event on this page and redirect to index page 只有类似此页面上的“捕获按钮”事件并重定向到索引页面之类的内容
I think the only way to to it is with javaScript 我认为唯一的方法是使用javaScript
You can bind to "navigate" event . 您可以绑定到“ navigate”事件 。
$(window).on("navigate", function (event, data) {
var direction = data.state.direction;
if (direction == 'back') {
window.location.href='http://google.com';
event.preventDefault();
}
});
You can make the success page, let's call it SuccessRedirect
, redirect the browser (using javascript or HTML meta header, you can't use a HTTP header) to another page, SuccessActual
, that displays the success message. 您可以将成功页面命名为SuccessRedirect
,将浏览器(使用javascript或HTML meta标头,不能使用HTTP标头)重定向到另一个显示成功消息的页面SuccessActual
。
On the first visit to SuccessRedirect
page set a cookie, so that if someone visits it the second time (ie after clicking the Back button) and the cookie is already set, instead of redirecting to SuccessActual
it redirects to the homepage. 在第一次访问SuccessRedirect
页面时,设置一个cookie,以便如果有人第二次访问它(即单击“后退”按钮之后)并且cookie已设置,而不是重定向到SuccessActual
它将重定向到主页。
The cookie name should include some kind of payment transaction id, so that you display the success page for every payment transaction. Cookie名称应包含某种付款交易ID,以便您显示每笔付款交易的成功页面。
It's a bit hacky and it won't work if someone quickly clicks 'Back' multiple, but hey, it might work well enough. 这有点骇人听闻,如果有人快速单击“后退”多个按钮,它将无法正常工作,但嘿,它可能已经足够好了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.