Communication with webview

You must Login before you can answer or comment on any questions.

Hi,

I try to send signals to Titanium, here the code:

var webview = Titanium.UI.createWebView({
    url:'http://tools.webmasterei.com/tn/'
});
Ti.App.addEventListener('goUrl',function(_e){
    Ti.API.log(_e);
});
and here the HTML:
<html><head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
   $("a").click(function(event){
       Ti.App.fireEvent('goUrl',{url:$(this).attr('ref')})
   });
 });
</script></head>
<body>
<a href="#" ref="http://heise.de/">Link to other page</a>
</body></html>
But nothing on titanium level appears.

Any ideas? The HTML is remote. On web console I can see that the right url is parsing

2 Answers

I think what Sapan might have been trying to say is that javascript loaded from a remote server cannot access the Titanium namespace. So your Ti.App.fireEvent() call is not going to work if the HTML document was loaded from a remote URL.

You might be able to pull down the HTML with an HTTPClient, save it to the local filesystem, and load it into the webview. I've never tried that. It seems like an end-run around the security model, so I can't be sure it will work.

In url property of webview, give the html file path not link.

var webview = Titanium.UI.createWebView({ url:'/webview.html' //saved the html content into thins file and saved under resource directory });

Your Answer

Think you can help? Login to answer this question!