簡體   English   中英

用戶刷新網頁並重定向到另一個URL是可能的嗎?

[英]It is possible for user refresh webpage and redirect to another url?

我正在建立一個站點wordpress,我想在用戶刷新時重定向到頁面,重定向我的站點的主頁。 有可能的? 這個代碼可以吧?

$(window).unload(function()
{
    var reload = confirm("are you sure you want to leave?");
    if(reload)
    {
        location.reload(); // Refresh the site, not needed really.
        location.href = "http://example.com"; // Redirect.
    }
});

這段代碼對我有用

       <body onbeforeunload="return myFunction()">
        //modify your body tag

       myFunction(){
         event. preventDefault(); //for Mozilla browser only
        document.location.href="/";  //Redirect to your home
                                                               page 
       }

暫無
暫無

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

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