2

This is the opposite to most people's problems.

When you close Safari by clicking the home button, it saves the current state of the page. If the memory is fine, then when you reopen Safari - the view will be exactly as you left it. I basically want to log a user out when they hit the home button.

Is there a way to force the page to refresh when you open Safari again. I couldn't see anything about an event that could be used, or similar?

The best idea I could come up with, was to have a constant javascript function running and comparing a time, so that when they reopen and javascript resumes, it will recognise that the time is different.

lc_theTime = new Date().getTime();

setTimeout('checkTime()',1000);
function checkTime() {
    lc_newDateTime = new Date().getTime();
    if (lc_newDateTime > (lc_theTime + 1500)) {
        alert('ready to log out');
    }
    lc_theTime = lc_newDateTime;
    setTimeout('checkTime()',1000);
}

Obviously, I don't really want a javascript function running constantly - but I don't see an alternative to do what I'd like. Any help would be great!

andybarnes
  • 294
  • 1
  • 14
  • What is the problem of a javascript function run all the time here? – Ross Nov 19 '12 at 10:52
  • http://stackoverflow.com/questions/1210486/is-there-a-reliable-way-to-determine-if-a-browser-tab-or-window-is-inactive-or-n – Ross Nov 19 '12 at 10:52
  • Thanks for the speedy reply, Ross. There isn't a problem as such - it's just that it's not very elegant. And if I'm only checking every second - the view would be on screen for a split second before logging out. I'll investigate the onblur function - as that seems a good possibility, although not got the iPad to test on until Wednesday. – andybarnes Nov 19 '12 at 11:01
  • Ture, but sometimes a necessary evil when no events are available (perhaps you found one). Repeatedly running a function doesn't carry so much overhead if the function itself is light. And if that function is light you can speed it up... a lot. – Ross Nov 20 '12 at 09:39

0 Answers0