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";
}