1
votes

I have read multiple threads which claim that events can be fired from Webview to Titanium Native App, and hence tried all codes

Wrote:

function link_hit(str){
    var Ti = window.parent.Ti;
    Ti.App.fireEvent('fromwebview', {});
}

And wrote onclick in HTML page that calls link_hit(str)

In Titanium App - index.js (as I am using Alloy), I wrote:

Ti.App.addEventListener('fromwebview',function(e) { 
    alert(e.msg);
});

But the event is not getting fired from HTML to the Titanium, it keeps saying

[INFO] :   I/TiWebChromeClient.console: (main) [820851,822424] Uncaught TypeError: Cannot read property 'App' of undefined (55:http://www.example.com/testpage.php)

Also the Ti variable value as undefined. I have debugged it with Titanium info command.

I have already gone through threads like below and many more:

Ti.App.fireEvent - Reference error Ti is not defined https://developer.appcelerator.com/question/145838/alloy--titaniumapiinfo https://developer.appcelerator.com/question/86691/fireevent-from-webview-to-window

Titanium SDK - 3.5.1, and I am building app for android.

1

1 Answers

1
votes

Is this a local or a remote HTML page? If remote, then it will not work. Ti references can only be accessed from the local HTML page.