Is it possible to differentate between page refresh and close using the below method?
I want to open a popup window on closing the page and no开发者_JAVA技巧t during refresh of the page,
So what i am thinking to do is.
Clent
Send ajax request to server every x seconds.
Server
var timeout=0
var sec=0
while (sec>timeout)
{
open popup window
sec++;
if(request){
sec=0
}
}
Assumption
Timeout will be the maximum delay between requests during page rfresh.
So my questions are:
1)Will this technique work?
2)If not Is there any other method to do it?
3)If It works what is optimal value for Timeout variable(in seconds)
4)How can i implement a small example in django is much appreciated.
Just think for a simple solution. Why are you going for the complex solution? The simple way to get popup on page close is to just define the "window.onunload" event as shown below.
window.onunload = function(){
//Code to display Popup
}
Hope this helps you.
精彩评论