Webviews and fireEvent
Is there anyway to return a value to the webview after a fireEvent has been called? I don't want to use evalJS…
This is a quick test tried (which obviously doesn't work but it gives you an idea):
In my webview:
function test(){
alert(Titanium.App.fireEvent('test'));
}
In my local js:
Titanium.App.addEventListener('test', function(e){
Ti.API.info('Test local');
return 'Test webview';
});
Is there a way to do anything like this? I know I can do something similar with evalJS, but it won't work quite the way I want it to….
1 Answer
-
You need to setup a callback function, another event to fire back at the original file.
Titanium.App.addEventListener('01', function(e){ // do something Titanium.App.fireEvent('02', {return_value: 'return value'}); }); Titanium.App.addEventListener('02', function(e){ // do something with e.return_value; }); Ti.App.fireEvent('01');