SoFunction
Updated on 2025-04-06

Asp javascript implements the method of saving data when closing a window

How to save data when closing the window <SCRIPT language="javascript">
function IfWindowClosed() 

var win = null; 
try 

 = "ss"; 
if (  != "ss" ) 

win = ("","","width=100,height=100,left=10000,top=10000"); 
("();",0); 

 = ""; 

catch(e) 

win = ("","","width=100,height=100,left=10000,top=10000"); 
("();",0); 


 
("IfWindowClosed()",100); 
("();",510); 
</SCRIPT> 
--------------- 

Open the above file using the onunload event

To save the data file, the above file is used to detect whether the window is closed or refreshed.

IE5 is compatible. I used to judge before that IE5 does not support the closed attribute.
The above code has been tested many times and no problems have been found yet