题
在计算器当你问一个新的问题,你必须进入的问题,如果你决定离开该页你得到一个"你确定"确认。
我想做同样的在我的ASP.Net 应用程序:
用户已填写的调查问卷和有选择的商店他的答案temporarely.如果用户决定离开该页面没有temporarely存储他的答案,我们想确认,弹出和询问用户来存放他的答案。
两个问题:
什么是体面的方式表示确认弹出的页之前在卸载ASP.Net?
我知道beforeunload事件,但我不想让它一大javascript丐。我不想确认踢当用户的点击救按钮(其是节能的答案,无论如何)
解决方案
你必须写信的行动
哪 火灾之前的一页正在卸载.
<HTML>
<head>
<script>
function closeIt()
{
return "Any string value here forces a dialog box to \n" +
"appear before closing the window.";
}
window.onbeforeunload = closeIt;
</script>
</head>
<body>
<a href="http://www.microsoft.com">Click here to navigate to
www.microsoft.com</a>
</body>
</html>
其他提示
你要你的关注 "onbeforunload"事件 作为保存按钮你就可以做一些脚本逻辑,例如取消这一事件或人。
你可以试试这个:
<button onclick="javascript:doSend()">send</button>
<button onclick="window.xbuttons +='save ';">save</button>
<button onclick="window.xbuttons +='edit';">edit</button>
<script>
window.xbuttons = '';
window.onbeforeunload = function(){
if(!window.xbuttons.match(/save|edit/))
return "Do you want to leave this page?";
}
</script>
这事情你应该注意关于onbeforeunload:
- onbeforeunload 事件会在每一个(锚元)与href属性
- onbeforeunload 活动将在该文件的位置是改变通过javascript或通过改变该网址的地址吧
- onbeforeunload 活动将火的任何活动使用的 javascript: 伪协议
不隶属于 StackOverflow