javascript - 用户重新加载页面后 HTML/JQuery 重定向

标签 javascript jquery html

如何在用户重新加载页面后重定向到另一个 HTML 页面? 我不想自动执行此操作,因此无法使用 http-equiv="refresh"。 有任何想法吗?谢谢

最佳答案

下面的函数将确保您的页面是第一次加载还是页面刷新。然后您可以相应地添加您的代码。

<form name="refreshForm">
<input type="hidden" name="visited" value="" /> 
 // above Hidden field to store value of your page load status
</form>

function checkRefresh()
{
    if( document.refreshForm.visited.value == "" )
    {
        // This is a fresh page load
        document.refreshForm.visited.value = "1";
    }
    else
    {
             // This is a page refresh    
            window.location.replace("http://google.com");
             // Or , Use either of them
            window.location.href = "http://google.com";
    }
} 

关于javascript - 用户重新加载页面后 HTML/JQuery 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39911947/

相关文章:

javascript - CoffeeScript 窗口

javascript - 使用 jQuery 验证 Bootstrap 表单

javascript - 使用 javascript/Jquery 进行 Ajax

html - 在 CSS 中 float 导致元素向下移动

html - 在一个 Div 中居中一个 Div(以及根据内容的大小调整一个 div 的大小)?

javascript - 查看复选框是否被点击,直到被点击

javascript - D3.JS如何删除/更新

javascript - 使用图像映射在悬停时更改图像

javascript - Jquery自动刷新分页

php - 调用JS函数时销毁 session 变量