- We design and build extraordinary applications for companies looking to make the next great idea a reality.
- learn more
Really Simple History: Progress on title updates
A week after wondering whether title updates were worth the trouble in Really Simple History, I'm reconsidering my opinion. It turns out a couple of users had already tackled this problem and come up with some solutions to the worst issues. (That will teach me to post about RSH without keeping up to date on my own Google Group and issue tracker.) At this point I have Firefox, IE and Safari working. Opera is proving to be a bigger challenge.
My original problem was that when a user clicks the back button to
land on a previous history point, RSH can't update the document title
until the history change is already complete. That means the browser's
history entry for the new hash gets set to the document title that
matches the previous hash. The trick - as pointed out in the comments here
- is to simply reload the current hash after the title change is
complete each time a history callback gets triggered. That causes the
browser history stack to replace the incorrect title with the correct
one. This seems to do the trick in Safari and Firefox. The code looks
like this:
//Code here sets var winTitle to the correct title
/*Now change the DOM*/
document.title = winTitle;
/*Change it in the iframe, too, for IE*/
if (this.isIE) {
this.iframe.contentWindow.document.title = winTitle;
}/*If non-IE, reload the hash so the new title "sticks" in the browser history object*/
if (!this.isIE) {
var hash = decodeURIComponent(document.location.hash);
if (hash != "") {
var encodedHash = encodeURIComponent(this.removeHash(hash));
document.location.hash = encodedHash;
}
}
As
for IE, its history mechanism is a little different. History events are
keyed off of programmatic manipulation of an iframe. As a user of our
Google Group pointed out here,
all you have to do is keep the iframe's title in sync with the main
window's title. It takes a single line of JavaScript in the blank.html
file and a matching one in the code quoted above. That's right, IE
actually requires less work here than Firefox!
The real problem child is Opera, which doesn't behave as expected
when the current hash gets reloaded. The URL hash fragment is literally
being replaced by the exact same value, but Opera doesn't see it that
way; it acts as if the hash values are different and creates a second
history entry for the exact same URL. The result is that it takes two
clicks of the back or forward button to change application state. I'm
still looking for a workaround on this issue; if worse comes to worse,
title-change requests will simply get ignored in Opera.
At any rate, one edge case is cropping up even in the browsers that
do work. This is the same edge case that stumps a lot of RSH newbies -
including myself, when I first used Brad Neuberg's original version a
couple of years ago. That's the issue of how to handle a hashless
application URL. With any RSH application, the minute you start
creating history points, each one is associated with a unique hash
value in the URL (the part after the "#"). But many users will enter
the application at the root document URL, which has no hash. RSH
doesn't currently offer a graceful way to create a default application
state; it recognizes no history point associated with the absence of a
hash. This forces application developers to handle this case in their
own code, and often they choose to programmatically create a default
hash when the page initially loads. This can result in one of two
problems, depending on how the default hash gets set:
- When users click the back button to get back to the hashless
application state, the application immediately moves them forward to
the first hash. The problem of circular URL redirection has been around
as long as meta refreshes, but it's still annoying. - When users click the back button to get back to the hashless state,
the application does nothing. It simply retains whatever state it had
with the previous hash value. Again, this runs counter to user
expectations.
Regardless of which scenario occurs, title changes complicate the
issue. If the application author is manually creating a default history
point outside the normal mechanism, then it's hard for RSH to properly
coordinate title changes for that history point. You could end up with
some mismatches between browser title and actual application state. As
you can see from the code above, RSH can't reload just the hash value
if there is no hash value. Setting a blank hash to a string causes the
equivalent of reload, which opens up a whole separate can of worms.
That's why the code carefully handles a hash value of "".
Ideas, anyone?
Technorati Tags
Topics: Ajax Bookmarking, Really Simple History
Leave a comment
About Pathfinder
Recent
- Push Button Phones and the Limits of User Testing
- Firefox Plugin Malware ‘Trojan.PWS.ChromeInject.A’
- Pathfinder releases version 1 of the its Flash Platform microsite (codename Mica)
- Pimp my Rails: Five Plugins & Gems to Make Rails Better
- iPhone: Using Pre-processor Directives for Device Testing
- Subtle OpenGL Projection Matrix Difference Between iPhone Simulator and Device
- App Security: Throw Out the Org Chart!
- Pimp my jQuery: Five plugins to replace the features Prototype and Scriptaculous users expect
- Thanksgiving 2008: What We’re Thankful For (In Rails)
- iPhone SDK: Testing with TextMate & GTM
Archives
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006

