簡體   English   中英

瀏覽器的“后退”按鈕轉到倒數第二頁。 為什么?

[英]Browser's 'Back' button goes to second to last page. Why?

添加以下簡短的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;

我尚未對此進行測試,但請嘗試更換:

window.location.replace(string_url)

與:

window.location.href=string_url

讓我知道這是否可以解決問題或行為是否相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM