简体   繁体   English

关闭浏览器时,调用服务器端功能,然后显示警报消息

[英]On Closing of Browser,Call Server Side Function then Display Alert Message

My requirement is when I close the browser, I have to delete a record from a database and if during this deletion process, if any Exception raises then show alert and don't close the browser. 我的要求是,当我关闭浏览器时,我必须从数据库中删除一条记录,如果在此删除过程中,如果引发任何Exception则显示警报并且不要关闭浏览器。

My code is: 我的代码是:

 <body  onbeforeunload="javascript:return unlockOperationonMain()"></body>
function unlockOperationonMain()
    {

                    top.welcomePage.__doPostBack('Close', 'ApplicationInstance')
                     return '';
    }

function unloadFunction()
    {

                    deleteCookie();
    }

I am using .net 1.1. 我正在使用.net 1.1。 Problems I am facing is that when an Exception raises, there is an additional dialog box comes and asks 我面临的问题是,当引发Exception时,会出现另一个对话框,并询问

"DO You really want to navigate Press Ok to Continue and Cancel to.." “您确实要导航吗?按OK继续,然后单击取消。。”

I don't want this dialog box to come because in this dialog box if I press OK browser closes, but I have to show an alert and don't close the page in case of Exception . 我不希望出现该对话框,因为如果按OK,在此对话框中浏览器将关闭,但是我必须显示警报,并且在Exception情况下不要关闭页面。

Using JavaScript page-onunload to perform a server-end/database operation isn't reliable . 使用JavaScript page-onunload执行服务器端/数据库操作不可靠

There is no way to override browser behaviour to force the user to stay on the page. 没有任何方法可以覆盖浏览器行为以迫使用户停留在页面上。 If that were possible, there would be a lot of really frustrated users! 如果可能的话,将会有很多真正沮丧的用户! You should use some other methodology to remove the database entry (sessions and their invalidation perhaps?) 您应该使用其他方法来删除数据库条目(会话及其无效化?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM