admin管理员组文章数量:1391975
In javascript, I have a page A, which has a link to page B. B has javascript that redirects to another page C via window.location.href=""
. The problem is in IE 10/11, if i click back on page C, it goes back to page B, which redirects back to page C again. I want it so that it goes back to page A.
Can this be done?
Thanks
In javascript, I have a page A, which has a link to page B. B has javascript that redirects to another page C via window.location.href=""
. The problem is in IE 10/11, if i click back on page C, it goes back to page B, which redirects back to page C again. I want it so that it goes back to page A.
Can this be done?
Thanks
Share Improve this question asked Mar 21, 2017 at 20:18 omegaomega 44k90 gold badges286 silver badges523 bronze badges2 Answers
Reset to default 4You can add your own back button, which will go back two pages instead of one, and set its onclick
attribute to be:
window.history.go(-2)
That will bypass the redirect page.
EDIT: As @NelsonTeixeira clarified, you can create your own button, and label it whatever you'd like. For example:
<button onclick="window.history.go(-2)">Back</button>
Instead of blindly sending visitor of B to C you should use document.referrer to check where the user is ing from .
If referrer is A then goto C else goto A or if referrer is C goto A
Document.referrer at MDN
For example, you will put this code in page B:
var ref = document.referrer;
if(ref.includes("pageC.html")){
window.location.href="pageA.html";
}
else{
window.location.href="pageC.html";
}
本文标签: htmlHow to get go back two pages in javascriptStack Overflow
版权声明:本文标题:html - How to get go back two pages in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744600442a2615035.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论