![](/img/trans.png)
[英]Is is possible for user refresh webpage and redirect to another url at same time?
[英]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.