返回上一页跳过中间页面,返回上一页跳过敏感页面
2017-09-18 20:30
211 查看
常见一种情况,例如支付:
有如下三个页面:入口页面,填写金额页面,支付成功页面
其中支付页面在支付成功有会有一个返回上一页的按钮,点击就返回上一页,或者点击浏览器返回上一页会出现继续进入输入金额的页面。
现在解决这个问题
关键点:
history.replaceState(null, null, document.referrer);
document.referrer(改属性非常的脆弱,参考:http://driftcloudy.iteye.com/blog/986265)
location.replace
方案1:
添加中间空白页面:
agency.html,输入金额页面跳转和支付成功跳转,都是跳转到这个页面。
切记跳转代理页面的时候不要用location.relace("xx/agency.html");
这样处理的话会把来源页面的历史记录替换成代理页面,这样就无法判断来源了
输入金额页面:
替换当前页面的历史记录为代理页面:
支付成功的页面直接:
方案2,不需要中间件:
a.html
b.html
C.html
注意:
如果涉及跨域,必须使用代理的方式,history.replaceState不支持不同域名,location.replace没有跨域问题,history.replaceState和location.replace都可以删除当前页面的历史记录替换成指定的
有如下三个页面:入口页面,填写金额页面,支付成功页面
其中支付页面在支付成功有会有一个返回上一页的按钮,点击就返回上一页,或者点击浏览器返回上一页会出现继续进入输入金额的页面。
现在解决这个问题
关键点:
history.replaceState(null, null, document.referrer);
document.referrer(改属性非常的脆弱,参考:http://driftcloudy.iteye.com/blog/986265)
location.replace
方案1:
添加中间空白页面:
agency.html,输入金额页面跳转和支付成功跳转,都是跳转到这个页面。
if(/order\.html/.test( document.referrer)){ window.location.href = window.ptDomain + "person/welfare"; } else{ history.back(); }
切记跳转代理页面的时候不要用location.relace("xx/agency.html");
这样处理的话会把来源页面的历史记录替换成代理页面,这样就无法判断来源了
输入金额页面:
替换当前页面的历史记录为代理页面:
location.replace("./agency.html");
支付成功的页面直接:
location.history.back()
方案2,不需要中间件:
a.html
<p>我是aaaaaaaaaaaaaaaaaaa</p> <a href="./b.html">去bbbbbbbbb</a>
b.html
<p>我是b</p> <a href="c.html"> 去ccccccccc</a> <script> history.replaceState(null, null, document.referrer); console.log("后:",window.history) </script>
C.html
<body> <div id="wrap"></div> <p onclick="javascript:deleB()">我是c.html,点击跳过b</p> <script> function deleB(){ history.back(); } console.log(document.referrer) </script> </body>
注意:
如果涉及跨域,必须使用代理的方式,history.replaceState不支持不同域名,location.replace没有跨域问题,history.replaceState和location.replace都可以删除当前页面的历史记录替换成指定的
相关文章推荐
- 【android】关于多个activity页面跳转,跳过中间页面返回前边页面传值
- jsp页面返回上一页,在两个页面死循环
- 页面序号和返回上一页
- html 页面跳转 返回上一页 history 和 location
- php执行成功后返回前一页并刷新页面
- 怎么在新页面中返回到前一页浏览的历史位置?
- 利用js控制页面刷新以及返回上一页刷新
- js返回上一页并刷新、返回上一页、自动刷新页面
- 点击按钮,浏览器返回上一页,离开页面提示
- JS后退一页, JS返回上一页代码, JS返回下一页,JS返回第几页,JS页面跳转,JS引用
- js返回历史上一页并刷新页面
- PHP中如何返回前一页并刷新页面
- JS后退一页, JS返回上一页代码, JS返回下一页,JS返回第几页,JS页面跳转
- 分页操作时,点击上一页或下一页,当返回到指定页面时,该页面被选择的复选框任然被勾中
- 页面返回 上一页 下一页
- JS返回前一页(或关闭本页面,返回首页)
- 打开新页面,返回前一页
- aspx中页面按钮写返回上一页代码
- 返回上一页并强制页面刷新
- js 页面history.back()返回上一页,ios 不重新加载ready的解决办法