location.replace(),并在返回数据时移动到新页面
location.replace() and move to a new page when data is returned
从$.post()
返回一些数据后,我需要移动到另一个页面?
verifystudent.html:
$.post('students/verify.php',
function(results){
preventdefault();
location.replace("verifystudent.html");
window.location.href = "completed/student_result.html;
}
基本上,当数据被接收到verifystudent.html
时,它应该移动到student_result.html
,并且当点击浏览器后退按钮时,它应避免转到verifystudent.html
。我该怎么做?
试试这个脚本,它会阻止浏览器的后退按钮,所以在verifystudent.html 中使用它
<script type = "text/javascript" >
history.pushState(null, null, 'pagename');
window.addEventListener('popstate', function(event) {
history.pushState(null, null, 'pagename');
});
</script>
希望这能有所帮助。
使用SessionStorage保存应用程序的状态。您可以创建一个密钥来标记学生已验证。
加载验证页面时检查此密钥,如果学生已经验证,则使用location.replace
更改URL。
另请阅读这篇关于防止用户转到上一页的文章。
对于您的第二个问题",当点击浏览器返回时,应避免转到verifystudent.html"
我在搜索同一个问题,在一个网站上发现了以下代码。想在这里分享一下:
function noBack()
{
window.history.forward()
}
noBack();
window.onload = noBack;
window.onpageshow = function(evt){ if(evt.persisted) noBack(); }
window.onunload = function(){ void(0); }
然而,正如许多开发人员所指出的,这从来都不是一个好的做法,出于各种原因都应该避免。
您可以在verifystudent.html
上使用JQuery navigation
事件将用户发送到所需的页面
$(window).on("navigate", function (event, data) {
var direction = data.state.direction;
if (direction == 'back') {
window.location.href = "completed/student_result.html;
}
}
相关文章:
- 以下数据布局在设置显示上向上移动:无
- 如何在剪切/粘贴/移动后在contentEditable DIV中保留与XML相关的数据
- 如果我在页面之间移动,Jquery 数据表行事件会卡住
- 如果上一个
为空,则向上移动表数据 d - 如何在页面之间导航后停止jquery移动中的重复数据
- 尝试在移动优先应用程序中从 SQL 数据库获取数据时出错
- 如何使用jquery移动数据块
- 在线/离线数据更新移动最佳实践
- 从页面上点击的链接中删除数据,然后移动到下一页&在CasperJS中重复
- 当一个字段已满时,将数据条目移动到下一个字段-JS制表
- 当移动到“外部”版本时,“内部”成功 AJAX 中的“数据”变量应该更改为什么
- 如何在移动屏幕上居中“获取数据”
- 使用数据发布更改页面 jQuery 移动
- 数据表移动行按钮
- 来自第三方身份验证的 Firebase 身份验证数据在移动 safari iOS8 中始终为空
- 视频标签仅在移动设备上调用一个字节的数据(Node.js)
- 将一些 JSON 数据移动到唯一的 Div 中
- 将数据移动到$.ajax's out
- 将数组数据移动到分部中
- 如何在不移动过滤功能的情况下将一组过滤后的数据移动到另一个工作表