如何捕获浏览器关闭事件并通过javascript对该事件的Web服务方法发出请求 [英] How to capture browser close event and make a request to web service method on that event through javascript

查看:92
本文介绍了如何捕获浏览器关闭事件并通过javascript对该事件的Web服务方法发出请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我通过第三方设备使用它在我的页面上的api进行录制。通过asp.net Web服务启动和停止。

I have a application where I am doing recording through a third party device using it's api on my page.Recording is started and stopped through a asp.net web service..

我能够在正常情况下通过javascript启动和停止录制,并且functiaanilty在所有浏览器中都能正常工作。

I am able to start and stop the recording through javascript in normal cases and the functiaanilty works fine in all browsers.

但是,一次意外地一个用户没有停止视频,关闭浏览器,在这种情况下录制无法停止..它继续录制..

But,once accidently one user without stopping the video,closed the browser in which case the recording could not be stopped..and it went on recording..

所以,请建议我一个方法,以便我可以通过请求服务器在浏览器关闭时自动停止录制..

So,please suggest me a way so that I can pass a request to the server to stop the recording automatically when the browser is closed..

推荐答案

你不能。

您可以使用 onBeforeUnload ,但您无法发出请求(在大多数浏览器中)。

You can show a standard dialog or do a few fast not interactive operations like writing in localStorage, by using onBeforeUnload, but you can't make a request (in most browsers).

来处理浏览器关闭(或网络丢失或任何事件)服务器端的情况。

You have to handle the case of browser closing (or network lost, or any incident) server side.

这篇关于如何捕获浏览器关闭事件并通过javascript对该事件的Web服务方法发出请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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