Rumah >hujung hadapan web >tutorial js >asp javascript 实现关闭窗口时保存数据的办法_javascript技巧
关闭窗口时保存数据的办法 <script> <BR> function IfWindowClosed() <BR> { <BR> var win = null; <BR> try <BR> { <BR> window.opener.name = "ss"; <BR> if ( window.opener.name != "ss" ) <BR> { <BR> win = window.open("quit.asp","","width=100,height=100,left=10000,top=10000"); <BR> window.setTimeout("window.close();",0); <BR> } <BR> window.opener.name = ""; <BR> } <BR> catch(e) <BR> { <BR> win = window.open("quit.asp","","width=100,height=100,left=10000,top=10000"); <BR> window.setTimeout("window.close();",0); <BR> } <BR> } <BR> <BR> window.setInterval("IfWindowClosed()",100); <BR> window.setTimeout("window.close();",510); <BR></script>
---------------
用onunload事件打开上面的文件
quit.asp为保存数据的文件,上面的文件用来检测窗口是关闭还是刷新
ie5兼容,以前使用 window.opener.closed来判断,ie5不支持closed 属性。
上面的代码经过多次测试,暂时没有发现问题