Matt Snider JavaScript Resource

Understanding JavaScript and Frameworks

Friday, September 21, 2007

More on Really Simple History

So contrary to my last post, it does work in Internet Explorer. I had accidentally overwritten their blank.html file with the one used by YUI. This file is required for the IE IFRAME and contains a callback to “window.parent” (the browser window that you are using dhtmlHistory in). If the following is missing, then IE won’t work:

<script language="JavaScript"> function pageLoaded() { window.parent.dhtmlHistory.iframeLoaded(window.location); } </script> <body onload="pageLoaded()"></body>

I never did manage to get it working in Safari 2 or 3, so if anyone knows of a back history method that works in Safari, please leave a comment.

I have two working demos now, one uses the files provided and the other uses my cleaned up YUI version.

Standard Version

My YUI Version

What is the difference?

My version uses my favorite pattern (Module) instead of the Prototype Pattern, which reduces confusion and truly makes functions and variables private. I use compliant DOM method, “document.createElement()”, instead of “document.write”. This also eliminates the need to use “document.getElementById()”. Also, as long as you wait for the DOM to be ready, leveraging “YAHOO.util.Event.onDOMReady()”, you do not need the “window.dhtmlHistory.create()”, as everything can be done in your initialization method. Lastly, because we are leveraging YUI, I demonstrated the unobtrusive way to do this demo. You could also remove the JSON Object and replace it with something simpler that meets your needs and that will save you another 5k.

posted by Matt Snider at 7:08 pm  

2 Comments »

  1. Matt, thanks for the great post on RSH. I am the new maintainer of the library and am about to release a beta of the 0.5 version. I am puzzled by one aspect of your revisions, and I’m wondering whether you can explain. The reason RSH 0.4 uses document.write to create its hidden textarea is that this causes the textarea to exist in the DOM when the page is loaded, even when it’s loaded from the cache. This means that you can navigate through your RSH-enabled application, then navigate to a different site, and then use your back button to navigate back. When you land back within your own app, all of your history will be preserved. I tried going down a path similar to yours but found that adding the textarea after DOM loaded caused all values saved to that textarea to get hosed when you navigated away and back. Did you find a way around this problem, or were you only testing your solution while staying within your own app? I’d love to get away from document.write if possible, but my 0.5 beta is going to include it for now.

    Comment by Brian Dillard — October 22, 2007 @ 3:00 pm

  2. [...] More on Really Simple History [...]

    Pingback by News: Really Simple History | Matt Snider JavaScript Resource — October 24, 2007 @ 2:08 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress