添加这段简短的 js 代码后:
$(document).ready(function() {
//check to see if it's an external link and if so 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;
}
});
});
当有人点击链接(例如页面 A)时,它会弹出警告,然后在一段时间后将用户重定向到新网址(例如页面 B)。
但是,当有人单击页面 B 上的浏览器“后退”按钮时,它并没有像预期那样将用户带到页面 A,而是实际上将用户带到了页面 A之前查看的页面。
确实很奇怪。 有谁知道为什么吗?
先谢谢了!
最佳答案
window.location.replace(string_url)
将当前历史记录条目替换为 string_url
。您应该设置window.location.href
:
window.location.href = string_url;
关于javascript - 浏览器的 'Back' 按钮转到倒数第二页。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4371751/