浏览器在asp.net中关闭之前保存数据 [英] Save data before browser closed in asp.net
本文介绍了浏览器在asp.net中关闭之前保存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要求我必须检测浏览器关闭以及浏览器选项卡关闭。
如果用户点击浏览器关闭按钮或尝试关闭然后我应该显示一个对话框(有2个按钮退出并取消)你真的想退出吗?如果用户点击退出,则保存其工作数据并关闭浏览器。
谢谢
Prafulla
I have a requirement that I have to detect browser close as well as browser tab close.
If a user will click on browser close button or trying to close the tab then I should display a dialog box(has 2 button exit and cancel) that " do you really want to exit " if user clicks on exit then the save its worked data and close the browser.
Thanks
Prafulla
推荐答案
检查以下链接
[ ^ ]
这里应该是javascript或jquery。在服务器端检测很困难(但我认为有一些可能的解决方案)。 Bcoz在处理您的请求时,用户可能已经关闭了该选项卡。所以要避免使用javascript更好,因为它可以轻松检测到用户活动。
Check the following link
Browser/tab close detection using javascript (or any other language)[^]
Here this should be either a javascript or an jquery. It''s difficult(but I think there are some possible solutions) to detect on the server side. Bcoz while the time your request is processed , the user might already closed the tab. So to avoid that it is better to use javascript as it could detect the user activity easily.
按照文章 - 在浏览器关闭时或退出页面时保存更改 [ ^ ]。 />
您需要使用 window.onbeforeunload [ ^ ]事件。
Follow the article - Save Changes on Close of Browser or When Exiting the Page[^].
You need to use window.onbeforeunload[^] event.
window.onbeforeunload = check;
function check() {
var response = confirm("Are you sure you want to exit this page?";
if(response == true)
{
// Do what ever you want to do. Call function to save data.
}
}
参考 - 关于浏览器关闭的Asp.net会话 [ ^ ]了解如何通过调用Web服务将数据存储在浏览器上。
Refer - Asp.net session on browser close[^] to know how it stores data on browser close by calling a web service.
这篇关于浏览器在asp.net中关闭之前保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文