How to capture browser tab/window close event in 4GL program?
The OPTIONS ON TERMINATE SIGNAL can be used to catch the close tab/browser event in 4GL program.
Below is an example program to demonstrate the subject functionality:
options_on_terminate_signal.4gl
DATABASE test1 MAIN DEFINE cnt INTEGER OPTIONS ON TERMINATE SIGNAL CALL tb_insrt MENU COMMAND "RECREATE TABLE" WHENEVER ANY ERROR CONTINUE DROP TABLE cl_term WHENEVER ANY ERROR STOP CREATE TABLE cl_term( f_int INTEGER ) COMMAND "OPEN EXCEPTION" OPEN WINDOW w1 WITH FORM "testform" COMMAND "CHECK TABLE REC" SELECT COUNT(*) INTO cnt FROM cl_term DISPLAY cnt COMMAND "EXIT" EXIT MENU END MENU END MAIN FUNCTION tb_insrt() INSERT INTO cl_term VALUES ("1") END FUNCTION
Following is the instruction on how to utilize the above program:
- Set the correct DATABASE in 4gl
- Compile and run the program
- Click "RECREATE TABLE"
- Click "CHECK TABLE REC" (to make sure that the table is empty. Once you close the browser tab/window, the table will be populated with one row of data)
- Close the browser tab/window, this event will trigger ON TERMINATE to call the tb_insrt() function which will populate the table with one row of data (Note: error, such as the OPEN EXCEPTION also triggers ON TERMINATE option)
- Run the program again and click "CHECK TABLE REC" button. It shows you count of inserted rows into the table
Lycia Documentation