I have this web page that sends a start real-time tracking command to GPS devices all over. The way the code is currently written fulfills its purpose as long as the page is actively loaded. However, if the user shuts down the browser or the computer, the device does not receive the stop real-time tracking command since the program is not running.

What I would like to accomplish is to create a script or service that will keep track of when a device needs to stop reporting in the event the user forgot to stop the real time tracking. I want to implement this feature for two reasons. First, the constant (non-stop) reporting becomes a billing issue for the company and second the devices are battery operated and the issue of energy consumption plays a big part.

What I was thinking on doing is implementing an AJAX script that will access the web method at the end of a specific interval but I believe this implementation will not work either. I tried to use the setTimeout() method with Ajax and it did not go very well.

I need some help and I would appreciate any input that would put me back on track with this project?

Thank you,

Have you considered using an Page_Unload method, and then backing it up through javascript on the <body onUnload="stopDevice()"> where stopDevice() is a javascript function?

This way you can have your C# or VB.NET to end your device transmission and a javascript backup just for insurance.

I have never dealt with the situation you are in, so I cannot be very good help, but hopefully I can lead you into a better direction.

Thank you for your reply and you definitely gave me some good idea on how to proceed. The question is: would this method also works if the user terminate the session by just closing the browser? I am really new to this javascript stuff but it doesn't appear to be a very difficult language. My real problem is that I don't know enough of it to be able to get things done fast enough.

Sure, here's a detailed explanation of what you can use, and what you might have to:

http://www.codeproject.com/useritems/Save_on_Close_of_Browser.asp

The one problem you will face is that javascript is client based, so if they have it disabled it will not work for them. You MIGHT be able to run the javascript server side since you're using asp.net, but I cannot guarantee that. You can use what you see here for an explanation on what to look for if you plan to write your own private function via VB or C#, or the like. I, personally, like to make sure all sides are covered. I would use the javascript, all functions for all browsers with if statements to determine which browser is which, and use the behind coding to make sure the connection is closed. I don't find a problem adding the extra code as it is only extra insurance, which I believe is necessary.

thank you for the link, though I understand some of the code on that page, but most of goes right over my head. For now I think it is safe to program a quick disconnect method in the event a user exited the page in question. later, I can take my time implementing a method that will cover all bases.

Thank you very much for your help.

No problem. Do you best to make sure they disconnect from the popular browswers (IE, FireFox, Netscape, Opera, and Safari). Wish I could be more help.

I think most browsers still execute the page unload event when you close them. You can always try it and see how it goes ;)

I think most browsers still execute the page unload event when you close them. You can always try it and see how it goes ;)

Actually, IE responds better to "onBeforeLoad", though it is not an option for other browsers :D

This article has been dead for over six months. Start a new discussion instead.