Using Javascript to disable the browser back button
With the rise of Ajax in web development, a lot of talk has been going on about how to deal with page state-persistence and search engine indexing of Ajax sites. Largely because Google somewhat recently released a white paper on how to create state-persistence and better Ajax indexing, a new procedure for dealing with this has emerged: dynamic URL hashing via Javascript. Facebook and Twitter are a couple of the big boys whom are already using this. It goes a little something like this: upon an Ajax request, a page should use javascript's location.hash property to dynamically change a hash in the page's URL so that the address reflects the new state of the page. For example, if one has a page that dynamically, through Ajax, shows 2 separate views of imagery and another of calendar events, the view that shows imagery should have a hash with the word imagery, while the other view a hash with the word calendar (#calendar). This way, one's Ajax page and Google will "know" the difference between the 2 URLS and correctly represent what needs to be represented.
I didn't know about the location.hash property until Google's white paper, mostly because I had little reason to use it before Ajax. Besides being useful for Ajax, it can also be used as a browser hack for effectively killing the browser back button. All one needs to do is set this property within a loop, run through it about a hundred times and no more back button (see code below). So far, I've only tested it on Firefox but I'm sure a good portion of the other browsers are affected by this.



0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home