views:

103

answers:

4

I am curious if there is a way to detect the browser refresh event in javascript specifically. We are using the jQuery.address plugin to provide forward and back button functionality to AJAX functions. The problem I am facing is that this plugin does not seem to detect if the user has refreshed the page.

This code is executed each time the user moves forward or back in the browser history. I would also like it to exexute when the user refreshes.

 $.address.init(function(event) {
}).change(function(event) {

        SummaryDiv.SwapPanels(newPanelID);
    }

Any ideas?

+1  A: 

On a page refresh, the javascript is also reloaded. So couldn't you specify what you want to happen directly in jQuery's ready method?

kingjeffrey
+1  A: 

A naive attempt of mine would be to simply store the current state into some cookie after each change and simply load them again on each page load.

LukeN
This is how I would do it, without looking up other methods. But know that this method could be easily avoided/edited by the user.
Capt Otis
As could the whole website by disabled Javascript :)
LukeN
Im trying this. This seems to be a common workaround.
Nick
A: 

Found this on the web for you...

Has both a javascript clever method along with a cookies method.

http://www.tedpavlic.com/post_detect_refresh_with_javascript.php

Capt Otis
A: 

I was able to force the change event code to run on refresh by

  window.onload = $.address.update(function(){    
...
})
Nick