
您好,正如您在圖片上看到的,在我的網頁中,我有幾個頁面可以重定向到同一頁面。在示例中,兩個頁面:
example.com/content.html -> example.com/news.html
example.com/files/actual.html -> example.com/news.html
我想在頁面上啟用一個按鈕,該按鈕example.com/news.html可以回傳到完整的源參考網址
因此,例如,如果用戶 Aexample.com/news.html通過example.com/content.html他的“回傳”按鈕被重定向到應該指向源 URL ->example.com/content.html
我已經嘗試過 JS 屬性
var referrer = document.referrer;
console.log(referrer);
但它只回傳域名example.com而不是完整的 URLexample.com/content.html
任何感謝表示贊賞。
uj5u.com熱心網友回復:
這取決于你需要什么。如果您總是有重定向,您可以使用:
window.history.go(-2);
否則,您可能必須使用歷史資訊來操作引數。
完整檔案:https : //developer.mozilla.org/en-US/docs/Web/API/History_API
uj5u.com熱心網友回復:
你所要求的是不可能的。在現代瀏覽器中,重定向不會替換參考者,重定向也不會出現在window.history. 使用客戶端 JavaScript,與單擊將用戶直接帶到頁面的鏈接相比,無法判斷用戶是通過重定向來的。
作為解決方法,您可以更改重定向以添加引數。 example.com/content.html可以重定向到example.com/news.html?from=content.html 然后 JavaScriptnews.html可以查看 URL 引數以確定重定向的頁面。
或者,您可以使用服務器端解決方案。您服務器的訪問日志會記錄重定向。您可以檢查此日志檔案以確定重定向的頁面。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/346894.html
標籤:javascript html 网址
