2011-02-27 26 views
0

我有一個調查請求,將向小部分網站訪問者提供。我試圖找出在用戶離開網站時啓動調查的最佳方式。最初,我正在考慮用戶在關閉瀏覽器窗口時會發生什麼 - 但我擔心這可能會被棄用,並可能被瀏覽器取消。我想知道是否有人比我更聰明有一個想法,可能工作。用戶退出網站時啓動調查窗口

我使用的是燈箱式窗口詢問用戶是否會願意的一項調查顯示:

JQuery的

<script type="text/javascript"> 
     $(document).ready(function(){ 
      $("a#showSurvey").click(function(){ 
       $("#lightbox, #lightboxPanel").fadeIn(300); 
      }) 
      $("a#closeSurvey").click(function(){ 
       $("#lightbox, #lightboxPanel").fadeOut(300); 
      }) 
     }) 
    </script> 

HTML

<div id="lightboxPanel"> 
    <h1>We want your opinion.</h1> 
    <p>Would you be willing to take a short survey when you've finished viewing our site? 
    <p align="center"> 
    <a href="#">Sure</a> // launch the new window after a user is done with site?? 
    <a id="closeSurvey" href="#">No thanks.</a> //This closes the lightbox 
    </p> 
    </div> 
    <div id="lightbox"></div> 

我不知道,如果無論如何,有一個很好的方法來與JS做到這一點。也許這是應該在服務器端的會話中處理的事情。

任何意見,將不勝感激。

回答

0

你可以看看.unload()http://api.jquery.com/unload/並促使他們採取在$(window).unload().

$(window).unload(function() { 
    alert('Would you like to take our survey?'); 
}); 
+1

調查是否.unload工作當用戶離開某個域,或只有一個頁面? – Peachy 2011-02-28 15:03:41