如何在重新加载选项(浏览器)上限制页面加载? [英] How can i restrict page loading on reload option (browser)?
本文介绍了如何在重新加载选项(浏览器)上限制页面加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个jsp页面,我想阻止它重新加载,如果用户点击刷新然后必须显示一个对话框并要求确认/留在这里。如果用户点击确认必须提交表格,否则页面不应刷新。
i have a jsp page and i want to prevent it from reloading, if a user click on refresh then a dialogue box must be shown and ask for Confirm/Stay here. if user click on confirm the form must be submitted otherwise the page shouldn't refresh.
<script type="text/javascript">
window.onbeforeunload = function(evt) {
var message = 'Are you sure you want to leave?';
if (evt) {
document.forms["myForm"].submit();
}
else {
}
return message;
}
</script>
<form action="SubmitExam.jsp" method="post" id="myForm"> My Code</form>
推荐答案
你想做什么,不是可能使用事件,无法捕获此事件的返回,您可以做的是尝试在按下按钮重新加载或关闭标签之前进行用户回答
function onMouseLeave(e){
var pageX = e.pageX || e.clientX;
var pageY = e.pageY || e.clientY;
if (pageX < 0 || pageY < 0 || pageY < top) {
if(confirm('exit intension ?')){
alert('yes');
}else{
alert('no');
}
}
}
var body = document.body;
body.addEventListener('mouseleave',onMouseLeave);
这篇关于如何在重新加载选项(浏览器)上限制页面加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文