tags:

views:

75

answers:

3

First of all, these pages will never be on the web but will be in internal memory. They are a group of linked documents---an ebook.

http://www.anmldr.com/testdivs

When I click on the link in the first div, the second div becomes visible and the first div is hidden. The problem is with the browser's back button. If you then click on the back button, the URL updates but the first div does not show again. How can I correct the back button so that the first div shows? The link from the second div to the first div works fine but it is the browser back button that I do not know how to work with.

Thanks, Linda

P.S. These are using CSS3 so it is better to use a WebKit based browser.

A: 

Try this one:

http://www.mikage.to/jquery/jquery_history.html

Aykut
A: 

Any suggestions on how to solve this without using a framework like jQuery? All that I need is the one function. This will be used on an iPhone and so am trying to avoid unneeded frameworks.

Thanks again, Linda

Linda
+1  A: 

The way the jQuery plugin does it is to check the current URL every 100 milliseconds and as soon as the hash part of it changes, it triggers a reset of the content using a callback function. This is rather inefficient and crude, but I don't think there's another way. You can do this by adding this script to the head:

<script>
  var lastHash = window.location.hash || "nothing";
  setInterval(function() {
    if (lastHash != window.location.hash) {
      if (window.location.hash == '#offscreen') {
       document.getElementById('offscreen').className = 'slideInFromRightToLeft';
       document.getElementById('div1').className = 'slideLeftOut imInvisible';
      } else {
       document.getElementById('offscreen').className = 'slideRightOut imInvisible';
       document.getElementById('div1').className = 'slideInLeftToRight';
      }
    }
  }, 100);
</script>

This way you can also remove the onClick handlers and place all the logic in this function.

Max Shawabkeh
Polling the hash is the only way. Is window.location.hash not universally available? It's a minor issue, but it's easier to use.
Benry
It is. Changed to reflect that.
Max Shawabkeh
I will definitely give that a try. You even used my CSS classes which is helpful. Thank you very much for your efforts.Linda
Linda
It doesn't work as written or I am doing something wrong.
Linda
Just rechecked and I can't seem to find a general problem (tested in Chrome and Firefox) though it didn't work when returning to the very first unhashed page (fixed in the last edit).
Max Shawabkeh
----------------
Linda
Do you mind if I share this with others?
Linda
That's what stackoverflow.com is for. :)
Max Shawabkeh
If I had enough points on here, I would vote. You solved a problem that I have asked a LOT of people. FYI, this will be used in a hybrid app on the iPhone. The pages will be in internal memory of the iPhone. None of the frameworks that are available (that I have found) allow for good navigation between separate pages. I am trying to mimic the transitions often used on the iPhone but between separate pages. Your code did the trick for transitions between div's on the same page. If I knew more info about you, I would put a comment in my pages. Thanks for your work.
Linda
I'm glad it's worked for you, Linda. As for voting, you can still mark the answer as accepted.
Max Shawabkeh