g_blnCheckUnload = true;
function RunOnBeforeUnload() {
if (g_blnCheckUnload==true) {
window.event.returnValue = '离开窗口将断开视频链接吗?';
}
}
<body onbeforeunload="RunOnBeforeUnload()">
当点击确定的时候 执行update语句 如何实现 跪求详细源码要达到的效果是 离开该页面或者关闭时提示用户 用户还是要离开 则执行sql改变状态。 在线等 跪求源码
function RunOnBeforeUnload() {
if (g_blnCheckUnload==true) {
window.event.returnValue = '离开窗口将断开视频链接吗?';
}
}
<body onbeforeunload="RunOnBeforeUnload()">
当点击确定的时候 执行update语句 如何实现 跪求详细源码要达到的效果是 离开该页面或者关闭时提示用户 用户还是要离开 则执行sql改变状态。 在线等 跪求源码
//AJAX异步调用后台方法
function WinClose()
{
var isClose=confirm('你确定要离开吗');
if(isClose){
PageMethods.UpdateDB(UpdateSecceed);
}
}
//执行后台函数的回调函数
function UpdateSecceed(result){
alert('成功');
}在后台cs页添加
[WebMethod]
public static void UpdateDB()
{
//执行SQL
}用AJAX这样就可以了
{
public AjaxMethod()
{ }
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public void Update()
{}
}
<body onbeforeunload="RunOnBeforeUnload()">
<script>
function RunOnBeforeUnload(){
if (confirm("Exit?")==true){
AjaxPro.Update();
}else{
alert("no exit");
return false;}
}
</script>
</body>
Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethod));
但关闭进程或关闭电脑会不执行