Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Communication between app and webview not working

$
0
0

Hi all,

I am trying to make the html code that is run in my webview communicate with the app. For this I fire global events from the html side for which I listen in the app.

function getHmtlBody() {
    return "<html><body><div id='testButton'>TEST BUTTON</div></body><script>var _button = document.getElementById ('testButton');" +
                        "_button.onmousedown = function () { alert (this.id); Titanium.App.fireEvent('fromwebview', {name:this.id}); return false; } </script></html>";
}
 
var textBody = Ti.UI.createWebView({
        width: '96%',
        top: '8px',
        html: getHtmlBody(),
        height: Ti.UI.SIZE,
        scrollable: false,
        color: "#000000",
        font:{fontFamily:'Arial',fontSize:14 } 
    });
 
Ti.App.addEventListener('fromwebview', function(e) {
        console.log('check');
        console.log(Object.keys(e));
    });
When running this code and clicking the TEST Button in the webview, the eventlistener isn't triggered. Does anybody see any problems with this?

I am testing on the iOS simulator, using Titanium SDK 3.5.1.GA running on a mac Thanks in advance!


Viewing all articles
Browse latest Browse all 8068

Trending Articles