Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.9.0
-
None
Description
I have an app with a custom URL protocol handler. If I load it via the custom URL, it calls my handleOpenURL JS function, as expected. But if I then change window.location.hash, and then load another URL in an iframe, handleOpenURL is called again with the same URL.
1. Create an iOS project according to the docs (http://cordova.apache.org/docs/en/2.9.0/guide_getting-started_ios_index.md.html#iOS%20Platform%20Guide)
2. Add this to the bottom of index.html, before the </body> tag:
<button id="test">test</button> <script type="text/javascript"> function handleOpenURL(url) { console.log(url); } var test = document.getElementById('test'); test.addEventListener('click', function() { window.location.hash = 'foo'; var frame = document.createElement('iframe'); frame.src = 'img/logo.png'; document.body.appendChild(frame); }, false); </script>
3. Add this to the end of your HelloWorld-Info.plist file:
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>com.mycompany.myscheme</string> <key>CFBundleURLSchemes</key> <array> <string>sample</string> </array> </dict> </array>
4. Run the app.
5. Create a web page somewhere outside of the app, with a link like this:
<a href="sample://page">(sample)</a>
6. Open the page in Safari and click the link.
7. The app will open, and in XCode's console, you'll see "handleOpenURL: sample://page".
8. Now click the "test" button in the app. This will change window.location.hash, and create an iframe.
9. In XCode's console, you'll see a second "handleOpenURL: sample://page", which shouldn't happen.