title: How to detect in iOS webapp when switching back to Safari from background?
body: <p>How can I build a webpage which is able to monitor when the page gets the focus, especially when Safari is in the background and the user switches Safari back to the foreground.</p>
  
  <p>The code below does not fire the event when switching to Safari on an iPhone</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/javascript"&gt;
        window.onfocus = function() { alert("onfocus"); };
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
      Main text
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>According <a href="http://www.quirksmode.org/dom/events/index.html" rel="noreferrer">http://www.quirksmode.org/dom/events/index.html</a> : Safari iPhone does not fire the event when the window gains the focus. </p>
  
  <p>So my question is still: how to detect by using Javascript on a web page within Safari for iPhone that the window receives the focus?</p>