[TIMOB-6426] MobileWeb: Add support for non-http protocols to Ti.Platform.openURL() and Ti.Platform.canOpenURL()
GitHub Issue | n/a |
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-12-13T16:13:45.000+0000 |
Affected Version/s | Release 1.8.0.1 |
Fix Version/s | Sprint 2011-50, Release 1.8.0.1, Release 2.0.0 |
Components | MobileWeb |
Labels | stage |
Reporter | Chris Barber |
Assignee | Anthony Decena |
Created | 2011-12-01T16:05:05.000+0000 |
Updated | 2017-03-03T23:16:55.000+0000 |
Description
Ti.Platform.canOpenURL() just returns true for any and all urls. Ti.Platform.openURL() performs an window.open() for all URLs.
For canOpenURL(), say true if url does NOT contain a ":" or it does contain a ":" but is http or https, otherwise false. It would also be nice to have checks for if running in a simulator, then blacklist known unsupported protocols. For example, iPhone simulator doesn't support mailto, tel, sms, itms, itms-apps.
For openURL(), simply do something like:
canOpenURL(url) ? window.open(url) : window.location = url;
Problem with window.location is we may accidentally redirect the browser to a malformed mailto: or something. Perhaps we need to create a dummy iframe and target it by name with window.open()?
Note: this needs to be tested on all browsers including devices (ios & android) and simulators.
Attachments
The test for the ':' in the canOpenURL() function would fail on a url with no protocol but with a port, ie: someplace.com:8080 which would not be uncommon in a mobile web app. I'll try and come up with something that covers as much as possible while still remaining rather simple.
Also need to support :// which means use the current protocol.
I did some research and if you detect a URL that can be opened by local process (i.e. iTunes, mail, or something), it says to do it in a setTimeout:
This is probably to allow the UI to refresh, perhaps in the event of a mouse up event on a button. You may want to checkout http://r.mzstatic.com/htmlResources/880B/web-storefront-base.jsz and http://r.mzstatic.com/htmlResources/880B/web-storefront-preview.jsz.
I added a uri parser for the canOpenURL() method. I also fixed the issue where urls were getting incorrectly assigned to open in the current window. Commit is here: https://github.com/Mindelusions/titanium_mobile/commit/43764ed6634728de6960da5e7d903867eb0cf2d6 Test page is here: http://mindelusions.com/boneyard/ti_mobileweb/platform_url_test.html
Closing ticket.