页面卸载事件触发 [英] page unload event fires

查看:174
本文介绍了页面卸载事件触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在test.aspx.cs页面上有一个test.aspx,test.aspx.cs页面..



,我有一个函数(save() )当我关闭test.aspx页面时,它用于保存test.aspx页面的值。



。我需要调用save()。我该怎么办?



请在证明解决方案时举个例子..





i尝试使用page_UnLOad()事件但nolt工作....

i have a test.aspx, test.aspx.cs pages..

in test.aspx.cs page, i have a function(save()) which serves saving the values of the test.aspx page.

when i am closing test.aspx page. i need to call the save(). how i can proceed??

please give a example when proving solution..


i tried with page_UnLOad() event but nolt working....

推荐答案

关闭浏览器或退出页面时保存更改 [ ^ ]


< pre lang =cs> function OnBeforeUnLoad(){

返回& quot;您输入的所有数据都将丢失!& quot ;;

//或者您可以在此处拨打ajax

}< / pre> ;







< body onbeforeunload =返回OnBeforeUnLoad()>
<pre lang="cs">function OnBeforeUnLoad () {
return &quot;All data that you have entered will be lost!&quot;;
// or you can make ajax call here
}</pre>



<body onbeforeunload="return OnBeforeUnLoad()">


请记住,您永远保证不会收到关闭页面的通知。即使您有防水Javascript,浏览器进程也可能崩溃或连接丢失。



如果您希望将在一个页面上输入的信息传递给下一个,您可以使用普通的HTTP方法(将其放入GET请求的URL或提交POST)。如果您希望在不使用保存或提交按钮的情况下保存信息,则应在每次更改时使用客户端JavaScript和AJAX保存信息。尝试在页面关闭时做任何事都很脆弱,应该避免。
Bear in mind that you can never guarantee to get notification of a page close. Even if you have watertight Javascript, the browser process can crash or the connection can be lost.

If you want the information entered on one page to be passed to the next, you can use ordinary HTTP methods (putting it in the URL for a GET request or making a POST submission). If you want information to be saved without the use of a Save or Submit button, you should be saving it each time it changes, using client-side JavaScript and AJAX. Trying to do anything on page close is fragile and should be avoided.


这篇关于页面卸载事件触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆