最近要搞一个当窗体关闭的时候弹出一张问卷调查(绝对是好事,不是弹什么广告之类的)
但是发现实在是很麻烦。所以请前辈们帮帮忙。
要有用的哦。。

解决方案 »

  1.   

    怎么会很麻烦呢?
    <body onunload="alert('a')">
      

  2.   

    这里有一种在模拟Form提交的方法,在ie6和ie7中是有交的,但是在ff中被无情的阻止了。   function  ForceWindow()  
       {
          this.r =document.documentElement;   
          this.f =document.createElement("FORM");   
          this.f.target="_blank";   
          this.f.method="post";   
          this.r.insertBefore(this.f,this.r.childNodes[0]);   
       }  
      
      ForceWindow.prototype.pop= function(sUrl)   
      { 
          this.f.action   =   sUrl;   
          this.f.submit();   
      }  
      
      function testClick(){
      var newwin=new ForceWindow();
      newwin.pop("http://www.baidu.com");
     } 
      用这种方法是可以实现弹出窗口的。另外要想在窗体关闭的时候弹出来,而刷新的时候不弹出。则又要加点东西了。
      
       function window.onbeforeunload()   
       {   
    if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey||event.ctrlKey)   
    {   
         //判断event.altKey是为了Alt+F4关闭的情况;判断event.ctrlKey是为了Ctrl+W关闭的情况   
         //document.body.clientWidth不包括滚动条,而关闭按钮恰好在滚动条右侧。   
                   testClick();
         window.event.returnValue="";   
         
    }    
        }   
      这样在关闭ie7浏览器的时候是有效的,但是有个问题,那就是ie7是有标签页的,如果我关闭标签页,它就不弹出来了
     /////////////////
     又是一个严重的问题啊。
     ////////////////