现在我有个一个页面载入成功后,当按浏览器的“后退”按钮时,我需要执行我指定的function,请问语法怎么用啊?

解决方案 »

  1.   

    function实现的是什么 window?
      

  2.   

    <!doctype html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta charset="utf-8" />
    <title>11</title>
    <script>
    window.onbeforeunload = function(){alert()};
    </script></head>
    <body>
    </body>
    </html>
      

  3.   

    onbeforeunload
    这个function不单单是后退,只要离开本页面都会做出提示的
    ------------------------------
    <script language="javascript">
    g_blnCheckUnload = true;
    function RunOnBeforeUnload() {
    if (g_blnCheckUnload) 
       {//注意异常的捕获
         try{
           window.event.returnValue = 'You will lose any unsaved content'; 
    }catch(e){}
     } }
    </script>
    <body onbeforeunload="RunOnBeforeUnload()">
    </body>