Browser's 'Back' button goes to second to last page. Why?
After adding this short js code:
$(document).ready(function() {
//check to see if it's an external link and if 开发者_如何学Pythonso do the splashpage
$('a').click(function() {
var $this = $(this);
//get the redirect url
var redirect_url = $this.attr('href');
var string_url = String(redirect_url);
if (string_url.indexOf("http") !== -1) {
$('#external_link_modal').modal({
overlayClose: true,
overlayCss: {
backgroundColor: "#ebebeb"
}
});
setTimeout(function() {
window.location.replace(string_url);
}, 2500);
return false;
}
});
});
When someone clicks on a link (say on Page A) it pops up a warning then after some time, redirect the user to the new url (say Page B).
However, when someone clicks the browser's 'Back' button on page B, instead of taking user to Page A like it's supposed to, it actually takes him to the page viewed before Page A.
It's really weird. Does anyone have any idea why?
Thanks beforehand!
window.location.replace(string_url)
replaces the current history entry with string_url
. You should set window.location.href
instead:
window.location.href = string_url;
I haven't tested this, but try replacing:
window.location.replace(string_url)
with:
window.location.href=string_url
Let me know if that solves the problem or if it exhibits the same behavior.
精彩评论