简体   繁体   English

付款后在浏览器中单击后退按钮可返回到其他页面

[英]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.

相关问题 在特定页面上单击浏览器后退按钮后如何重定向到主页 - How to redirect to home page after clicking browser back button, when on a particular page 得到确认页面后点击浏览器返回按钮 - Clicking the browser back button after getting the confirmation page 不允许将CSS携带到上一页(单击浏览器后退按钮后) - Not allowing CSS to be carried to previous page (after clicking browser back button) 单击浏览器的后退按钮时将客户返回到同一位置 - Return customer to same position when clicking browser's back button 单击浏览器的后退按钮时重定向到特定页面 - redirecting to a specific page when clicking browser's back button 单击浏览器上的后退按钮时如何加载确切的页面? - How to load the exact page when clicking back button on browser? 单击浏览器后退按钮时如何保持在同一页面上 - How to stay on the same page when clicking the browser back button 单击后退按钮“不起作用”时,重定向到其他页面 - Redirecting to a different page when clicking in the back button “not working” 页面重定向后单击浏览器后退按钮后上一页未加载 - Previous page not loading after clicking browser back button after a page redirection 单击浏览器后退按钮时,将用户带回上一页滚动到的位置 - Take User Back to Where They Scrolled to on previous page when clicking Browser Back Button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM