2011-01-22 5 views

답변

5

을, 당신은 windowunload 이벤트를 사용할 수 있습니다 개체를 닫거나 새 페이지로 이동하여 이전에 문서의 맨 위에 열린 시간을 기록한 창을 검색합니다. 예 :

<html> 
    <head> 
    <script type="text/javascript"> 
     var start = new Date(); 

     window.onunload = function() { 
     var end = new Date(); 
     var secondsOpen = Math.floor((end - start)/1000); 
     alert("Pop-up was open for " + secondsOpen + " seconds"); 
     }; 
    </script> 
    </head> 
    <body> 
    ... 
    </body> 
</html> 
+0

짧고 짧습니다. –

1

특정 시간대를 계산할 때마다 필자는 항상 날짜 개체를 사용하여 팝업이 열리면 변수에 새 날짜를 저장하고 해당 날짜를 현재 날짜로 뺍니다.

// Execute this when the popup opens 
var popup_opened = (new Date()).getTime(); 

// And this way you can get the time (in seconds) that the popup has been opened 
var current_time = (new Date()).getTime(); 
var time_spent_opened = (current_time - popup_opened)/100; 

당신은 또한 팝업이 기능을 사용하여 열려있는 여러 번 있었다 시간을 검색 할 수 있습니다 : 예를 들면 다음과 같습니다의 팝업 내에서

function getPopupTime() { 
    var current_time = (new Date()).getTime(); 
    return (current_time - popup_opened)/100; 
} 
+0

팝업이 닫혔는지 확인해야합니까? 아니면 더 잘, 어떻게해야합니까? – user586025

관련 문제