Opera: detecting backward, forward, updating and closing events

I am currently working on a jQuery plugin that tracks visitor behavior. Motions, clicks, scrolling and resizing are recorded and sent via Ajax to a location where this data is parsed and stored.

Initially, data is sent to the script when the user leaves the page. By "leaves" I mean updating, moving back and forth though history, closing a window / tab and navigating to a different address.

The solution works in all EXCEPT browsers for Opera. I am using jQuery 'unload' event which is not supported by Opera at all. None of them work or load.

The question is, how do you implement this functionality for Opera browsers?

One solution I had was to specifically use the poll function I created. This feature allows you to specify the interval that the content pushes to the server every "x" seconds. Setting this to 1 second specifically for Opera browsers will probably fix the problem, but it's an awful amount of overhead and requests don't always execute sequentially, etc.

Any suggestions or am I just sticking with the above option?

Thank!

I suppose I could just link you guys at the plugin source. http://www.thedrunkenepic.com/junk/jquery.mousalytics.js

Regarding the code above, add:

if(window.opera)
{
options.interval = 1;
}

      

On line 89 works fine. My only problem is overhead, so I'm still looking for a more elegant solution.

+2


source to share


3 answers


According to http://bytes.com/topic/javascript/insights/799229-browser-quirk-onload-onunload-do-not-fire-back-forward-refresh-opera Opera never fires onload / onunload events, so such functions are impossible without hacks.

http://dev.opera.com/articles/view/efficient-javascript/?page=4 seems to confirm this and basically states that opera is trying to maintain page state across requests.



If you invest further, http://unitehowto.com/Onunload indicates that this is possible with opera.io.webserver.addEventListener('_close', onunload, false);

(where onunload is a previously defined function) however it also indicates that this functionality is not consistent across all versions of the opera and may not work at all.

I think your best option is probably to use the poll option for Opera, or perhaps use server side validation for the current page and where it ends up in the history queue.

+2


source


Does this line add JavaScript for you?

history.navigationMode = 'compatible';

      



Source: http://www.opera.com/support/kb/view/827/

+1


source


I had the same problem and this saved my day:

if( typeof(opera) != 'undefined' )
{
    opera.setOverrideHistoryNavigationMode( 'compatible' );
    history.navigationMode = 'compatible';
}

      

More information on this issue can be found at: http://www.opera.com/support/kb/view/827/

+1


source







All Articles