Easy enough to register a custom protocol handler so that a native app gets launched by a URL in Safari. However, doing this leaves the current browser window open. If the app then provides a link back to a URL (via openURL), that url will open in a new Safari window, ignoring the existing window. I asked a question here about loading in the same window, and it was suggested that using #anchor tags to differentiate content but using the identical url would confuse Safari into reusing a window, but that isn't true. Safari launches a new window even when the URLs are absolutely identical, including the #anchor tag. My next thought was to close the window via window.close() javascript before opening the url for the native app. But I can't get it to work. If I use an ajax call for the url, it doesn't actually launch the native app. If I use window.open(url), it cancels the closing of the prior window, whether I open the url before or after calling window.close().
Does anyone know of a way to get the current Safari window to close before launching a native app via a URL?