I already discussed the HTTP status code hack as an alternative to the slowly dying CSS history hack. In this article I would like to introduce another way of history stealing, which doesn’t require the user to be logged in to an account at the webpage in question (in contrary to the status code hack).
All that’s needed for it to work is a webpage that renders diffrent content for returning visitors in comparison to new visitors. Even better: A page that redirects either returning or new visitors to another page.
Now to the trick: Create an IFrame inside a scrollable DIV (overflow:auto) and make the width and height of the DIV a lot smaller than the width and height of the IFrame. Next, search the returning visitor’s version of the page for a container with an ID that is NOT included in the new visitor’s version of the page. Preferably the container should be somewhere in the bottom and/or right part of the page. This could be a “last viewed articles” container on a shop page for example.
Now call the page in the IFrame and include the ID you found as a hash tag tot the URL, i.e. “http://www.example.com/somepage#returningVisitorsOnlyID”.
What happens then is the following:
If you are a new visitor to the page, it loads and since the ID of the hash tag can’t be found nothing special happens. If, however, you are a returning visitor, the page will load and jump to the container with the ID once it is found. At this point the DIV that’s wrapped around the IFrame will notice this jump and scroll itself down to that position.
Here is a code example and a proof of concept page using groupon.com.
<div id="box"> <iframe onload="check()" src="http://www.groupon.com#rail" /> </div>
This hack is working in all versions of major browsers except Firefox 4 and Internet Explorer 9.