Hello Group,
I am developing an utility that can determine whether a page is abandoned/closed by User while page is still loading. Sometimes an html page takes time to load and because of it is slow, an User might close the page i.e. abandoned.
In my javascript utility,
– On body’s onload method, I am doing following stuff which creates a div element and adds to the body element.
function
show(option)
{
//Remove the elment if it exists.
var tempEle = $(‘_pageloaded’);
if(tempEle)
{
tempEle.remove();
}
var
divLoad = document.createElement(‘div’);
divLoad.id =
‘_pageloaded’;
document.body.appendChild(divLoad);
}
– On Window.onunload method, I determining whether any element with id ‘_pageloaded’ is there or not and if it is not there then the page is abandoned and logging using servlet.
window.onunload = windowload;
var
pageloaded = document.getElementById(‘_pageloaded’);
var msg,isloaded ;
if(pageloaded)
{
isloaded = true;
}else
{
isloaded = false;
}
msg = ‘index.html’;
URL =
‘/PageImpressionServlet?page=’ + msg+’&loaded=’+isloaded;
//alert(URL);
new Ajax.Request(URL, {
method: ‘get’,
Any help/suggestion whether this should work or not?
Your help would be appreciateed.
– R