[英]want to redirect to my home page when user reload the page
當用戶按下瀏覽器的刷新按鈕時,我想重定向到我的主頁。
例。 當某些用戶位於我的應用程序的第二頁(例如www.mydomain.com/second.php)上並按下瀏覽器刷新按鈕時,我希望彈出一個javascript進行確認,並將用戶重定向到我的應用程序主頁(例如www.mydomain) .com),我想使用javascript。
您可以使用隱藏的輸入來完成此操作。 當用戶第一次登陸頁面時,將值設置為true
。 隱藏的輸入通常在瀏覽器刷新時保存,因此刷新頁面時,請設置為檢查隱藏的輸入是否設置為true
。 如果是這樣,請使用window.location
將用戶重定向到所需的頁面。
本頁描述了您要尋找的內容: http : //www.tedpavlic.com/post_detect_refresh_with_javascript.php
以下是直接從此頁面獲取的示例:
<html>
<head>
<script language="JavaScript"> <!--
function checkRefresh()
{
if( document.refreshForm.visited.value == "" )
{
// This is a fresh page load
document.refreshForm.visited.value = "1";
// You may want to add code here special for
// fresh page loads
}
else
{
// This is a page refresh
// Insert code here representing what to do on
// a refresh
}
} -->
</script>
</head>
<body onLoad="JavaScript:checkRefresh();">
<form name="refreshForm">
<input type="hidden" name="visited" value="" />
</form>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.