Send pressKey when tab / browser closed
-
- Profound User
- Posts: 25
- Joined: Mon Jul 03, 2017 1:35 pm
- First Name: Ed
- Last Name: Kidhardt
- Company Name: Conestoga Wood
- City: East Earl
- State / Province: Pennsylvania
- Country: United States
- Contact:
Send pressKey when tab / browser closed
I'm trying to detect when the user closes a tab / browser - I need to send a pressKey back to have my program clear some files. What's the best way to go about this?
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Send pressKey when tab / browser closed
You didn't say what programming language/environment you are in. I guess I'll assume RPG since it's the most popular?
I guess it's possible to use something like a JavaScript event to send a "pressKey" or something like that when a window is closed, but I personally prefer a different approach. Consider the situation where someone's phone/laptop battery dies, or the power goes out... there's no way you can send a pressKey in situations like that. Likewise, if the HTTP server (Apache) times out and kills the job, there will be no JavaScript events involved.
A better solution, in my opinion, is to register routines that RPG or ILE will automatically run when things are ended.
Examples of possibilities are the CEE4RAGE() API, which runs a procedure when the activation group is ended. The "On-Exit" opcode, which runs code when a routine ends (no matter what ended it), the CEERTX/CEEUTX APIs allow a procedure to run when something is ended abnormally, etc. These allow you to do your custom code no matter how something got ended, so you don't have to worry abnout whether a pressKey() was sent or a timeout or a power failure... it runs in any situation.
I guess it's possible to use something like a JavaScript event to send a "pressKey" or something like that when a window is closed, but I personally prefer a different approach. Consider the situation where someone's phone/laptop battery dies, or the power goes out... there's no way you can send a pressKey in situations like that. Likewise, if the HTTP server (Apache) times out and kills the job, there will be no JavaScript events involved.
A better solution, in my opinion, is to register routines that RPG or ILE will automatically run when things are ended.
Examples of possibilities are the CEE4RAGE() API, which runs a procedure when the activation group is ended. The "On-Exit" opcode, which runs code when a routine ends (no matter what ended it), the CEERTX/CEEUTX APIs allow a procedure to run when something is ended abnormally, etc. These allow you to do your custom code no matter how something got ended, so you don't have to worry abnout whether a pressKey() was sent or a timeout or a power failure... it runs in any situation.
Who is online
Users browsing this forum: No registered users and 3 guests