2011-01-22 16 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

関連する問題