0

I am using Ben Luptons's History.js in an iPad web app. When in full screen app mode I have a back button that when tapped calls History.back();

That works fine, unless you have run out of states to go back to. Essentially, on initial load, or if you hit back enough times to return to the original page that loaded.

I need to return the number of states available and only go back if there is one available. For example:

if( pagesAvailable > 0 )
    History.back(); 

I hope that makes sense and someone can offer some help

Thanks,

Will

will
  • 4,557
  • 6
  • 32
  • 33

2 Answers2

1

window.history.length returns the number of entries in the history object, according to MDN: https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history

However, this appears to be unreliable as mentioned in the question @PRNDL linked to.

jackwanders
  • 15,612
  • 3
  • 40
  • 40
  • Brilliant, thanks. The app I'm building is (for now) iPad only, so I can deal with that. – will Aug 15 '12 at 09:29
0

You could try checking the referrer?

if (document.referrer == "") {
    window.close()
} else {
    history.back()
}