Note that there are some explanatory texts on larger screens.

plurals
  1. POOpera: Detecting back, forward, refresh and close events
    text
    copied!<p>I'm currently working on a jQuery plugin that tracks a visitors mouse behavior. Movements, clicks, scrolling and resizing are all recorded and sent, via Ajax, to a location where this data is parsed and stored.</p> <p>Originally, the data is sent to a script when the user leaves the page. By 'leaves' I'm referring to refreshing, going back and forth though history, closing the window/tab and going to a different address.</p> <p>The solution works in all browsers EXCEPT for Opera. I'm using jQuery's 'unload' event which isn't supported by Opera at all. Neither is onbeforeunload or onunload.</p> <p>The question is, how do I implement this kind of functionality for Opera browsers?</p> <p>One solution I had was to make special use of a 'polling' feature I created. This feature allows you to specify an interval which pushes the content to the server every 'x' seconds. Setting this to 1 second specifically for Opera browsers would probably solve this issue, but it's an awful amount of overhead and the requests aren't always completed in sequence, etc ...</p> <p>Any suggestions or am I only stuck with the above option?</p> <p>Thanks!</p> <p><em>I suppose I could just link you guys to the plugin source. <a href="http://www.thedrunkenepic.com/junk/jquery.mousalytics.js" rel="nofollow noreferrer">http://www.thedrunkenepic.com/junk/jquery.mousalytics.js</a></em></p> <p>Regarding the code linked above, adding:</p> <pre><code>if(window.opera) { options.interval = 1; } </code></pre> <p>On line 89 works great. My only concern is overhead, so I'm still looking for a more elegant solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload