Javascript 浏览器&x27;s';背面';按钮转到倒数第二页。为什么?
添加此短js代码后:Javascript 浏览器&x27;s';背面';按钮转到倒数第二页。为什么?,javascript,browser,back-button,Javascript,Browser,Back Button,添加此短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')
$(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页)时,它会弹出一个警告,然后在一段时间后,将用户重定向到新的url(比如B页)
然而,当有人点击浏览器B页上的“后退”按钮时,用户并没有像预期的那样进入A页,而是进入A页之前查看的页面
真奇怪。
有人知道为什么吗
事先谢谢 我尚未测试此功能,但请尝试替换:
window.location.replace(字符串\u url)
与:
window.location.href=string\u url
让我知道这是否解决了问题,或者它是否表现出相同的行为。我没有测试过这一点,但请尝试更换:
window.location.replace(字符串\u url)
与:
window.location.href=string\u url
让我知道这是否解决了问题,或者它是否表现出相同的行为。
window.location.replace(string\u url)
将当前历史记录条目替换为string\u url
。您应该改为设置window.location.href
:
window.location.href = string_url;
window.location.replace(string\u url)
将当前历史记录条目替换为string\u url
。您应该改为设置window.location.href
:
window.location.href = string_url;
这里没有JS专家,但这是使用索引值与非索引值的问题吗?这里没有JS专家,但这是使用索引值与非索引值的问题吗?谢谢。这很有效,感谢您对浏览器“后退”按钮行为的解释。谢谢。这是可行的,我们很欣赏对浏览器“后退”按钮行为的解释。