[TIMOB-16478] Ability to fire event from a web view when the contents are loaded from a hosted site (e.g. non local resource)
GitHub Issue | n/a |
Type | New Feature |
Priority | Low |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | webView |
Reporter | Leor Brenman |
Assignee | Unknown |
Created | 2014-02-19T18:20:46.000+0000 |
Updated | 2018-02-28T20:03:17.000+0000 |
Description
Ability to fire event from a web view when the contents are loaded from a hosted site (e.g. non local resource)
If your web contents are stored locally in the assets folder, then the Ti.App.fireEvent works and the titanium app can respond.
e.g.:
Ti.App.fireEvent('app:fromWebView', { message: 'event fired from WebView, handled in Titanium' });
If the web contents are stored on a web site, then the event doesn't fire.
This has come up twice today, once with Scott's and once with Louisville, Gas & Electric.
Both prospects have existing HTML5 web apps that they would want to use with an Appcelerator container. Event firing is useful for normal native/web view interaction as well as for leveraging Analytics and Breadcrumbs for the web view by firing an event to the native app and having the native app fire an analytics feature event and breadcrumb events.
I have provided a sample app where you can switch between local and remote html resources (settable in index.xml). Screen shots are also attached.
After entering a stock symbol (AAPL) in the web view and clicking submit, the web view fires an event. The container has an event listener for the even and displays an alert.
If the web resources are local this works. If the web resources are remote, it does not.
We hope to get a workaround or a solution for this.
Is there some javascript library that can be added to the remote web app so that Ti.App.fireEvent will work
Attachments
Someone from the community did find dome hack/workaround: http://developer.appcelerator.com/question/115911/titanium-javascript-in-webviews-for-remote-urls
Bert created a workaround that resolves the issue for now (sample attached) but it is a little cumbersome so it would be nice to have this be part of the platform.
Workaround sample