title: Simultaneous redirect to App Store and another page
body: <p>After having completed an online registration process, I want to check if the user is using an iPhone, and in that case give the option of opening App Store to download the app. Here's what I've coded so far:</p>
  
  <ol>
  <li>In PHP, check <code>$_SERVER['HTTP_USER_AGENT']</code> for the presence of the substring "iPhone".</li>
  <li>If so, output JavaScript code that, before redirecting to the welcome page, offers the possibility of going to App Store using a confirm box.</li>
  <li>Redirect to <code>itms-apps://itunes.apple.com/url-to-my-app</code> using <code>window.location = ...</code> in JavaScript.</li>
  </ol>
  
  <p>This works. However, when the user once again opens Safari, the page which I redirected from is still open. This doesn't make any sense in my case. I want to redirect to the welcome page <em>regardless</em> of whether the user chooses to open the App Store. If I try to write another <code>window.location</code> line below the first one to perform a second redirect, Safari simply skips the link to the App Store.</p>
  
  <p>I've considered redirecting from a hidden iframe, placing some kind of timer on the second redirect, experimenting with different combinations of JavaScript and HTTP header redirects and so on. None of the solutions I've thought of so far seems really solid, though. How do I do this if I want it to work gracefully across browsers and versions?</p>