-
detect average swf play time
Hi,
i'd like to detect the time of my swf being viewed before gets closed, or get to another page or the browser window gets closed. how do i achieve that? i dont have the access to the onClose() function. thanks in advance.
-The Dancin kidd
-
in action's panel of frame one of main timelines
Code:
getURL("javascript:document.body.onunload=function(){alert('swf played for: '+(playtime/60000).toFixed(2)+' minutes.');};this.update=function(a){playtime=a;};history.go(-1);");
var start=getTimer();
setInterval(function(){getURL("javascript:update("+(getTimer()-start)+")")},1000);
-
-The Dancin kidd
-
-
=( it doesnt work when user closes the window. without warning, there is not enuff time to access the database to update the counter. any other clue =(
-The Dancin kidd
-
call the javascript function once immediately, and reduce the interval. now its polling only once per second, and doesnt start for one second.
Code:
getURL("javascript:document.body.onunload=function(){alert('swf played for: '+(playtime/60000).toFixed(2)+' minutes.');};this.update=function(a){playtime=a;};history.go(-1);");
var start=getTimer();
function update(){getURL("javascript:update("+(getTimer()-start)+")");}
update();
setInterval(update,1000);
-
huh? but when window is closed, javascript lost its working environment and wont continue anymore. remove the alert box and try it yourself.
thanks though
-The Dancin kidd
-
the onunload fires before the window closes - javascript doesnt lose it's 'environment' in any case - the script will stop all script op execution until each statement is resolved. change the alert to a prompt('',''); followed by a window.open('http://www.flashkit.com'','',''), run the script, get the prompt, leave for 3 days, come back, answer the prompt and that window will still open. and yes, well, taking the alert out would definitely mean i wouldnt see the alert. not sure what you're talking about with the database - i dont see any mention of anything besides wanting to tell the user how long he was there - thus the alert. however, assuming you want to post the results serverside ? and maybe open that page ? instead of alerting - this works
Code:
getURL("javascript:window.onunload=function(){window.open('http://www.yoursite.com/howlong.txt','','');};history.go(-1);");
var loader=new LoadVars();
var start=getTimer();
function update(){loader.playtime=getTimer()-start;loader.sendAndLoad("http://www.yoursite.com/howlong.php",loader,"POST");}
setInterval(update,500);
and howlong.php would be
Code:
<?php fwrite(fopen("howlong.txt","w+"),"SWF played for ".$playtime/60000." minutes."); ?>
-
hmph wasnt sure this would work - it does
Code:
getURL("javascript:window.onunload=function(){window.open( 'http://www.yoursite.com/howlong.txt','','');};history.go(-1);");
var loader = new LoadVars();
var start = getTimer();
function update(){
loader.playtime = getTimer()-start;
loader.sendAndLoad("http://www.yoursite.com/howlong.php", loader, "POST");
}
loader.onLoad=update;
update();
-
that would generate a popup window, it is a disturbance to the user experience =(
-The Dancin kidd
-
then don't open the window... it's only included as a demonstration - take that out and the results are still saved to the data file, display it however you want.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|