簡體   English   中英

JS事件離開頁面並返回

[英]Js event leaving page and returning

我正在尋找一個事件,當用戶離開頁面然后返回時。 用例是用戶在頁面上,需要離開以安裝一些軟件。 完成后,它們將返回原始頁面。 我需要知道用戶何時返回,以便頁面可以檢查安裝情況,然后轉發到另一個頁面。

您可以使用load / unloadready事件和localStorage來保存案例的狀態。

$(window).load(function() {
    if(localStorage.getItem("installing") === "true"){
       localStorage.setItem("installed", true);
       window.location.href = "/redirect-page";
    }
});

$(document).ready(function() {
    if(localStorage.getItem("installing") === "true"){
       localStorage.setItem("installed", true);
       window.location.href = "/redirect-page";
    }
});

$(window).unload(function() {
     localStorage.setItem("installing", true);
});

JavaScript版本:

window.load = function(e) {
    if(localStorage.getItem("installing") === "true"){
       localStorage.setItem("installed", true);
       window.location.href = "/redirect-page";
    }
};

window.unload =function() {
     localStorage.setItem("installing", true);
};

暫無
暫無

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

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