Pmpha
Pmpha

Reputation: 25

Communication between Titanium app and remote webview

I want to call a function onload in a remote webview, for now i have the following code:

index.xml:

<Alloy>
  <Tab title="Livestream" onClick="initialize">
    <Window>
       <WebView id="webview" url="http://urltowebsite.com"/>
   </Window>
  </Tab>
</Alloy>

And the controller of index.js:

$.webview.addEventListener('load', function(){
  var data = "Hello world!";
  $.webview.evalJS("foo('" + data + "'););
});

And in the index.html of the remote webview:

<script type="text/javascript">
  function foo(data) {
    alert(data);
  }
</script>

nothing happens, when the view is loaded in the webview of the application...

Thanks in advance!

Upvotes: 1

Views: 821

Answers (1)

Ashish
Ashish

Reputation: 2018

The way of passing the arguments is wrong . Below is correct way to send your parameter to the webview.

$.webview.addEventListener('load', function(){
    var data = "Hello world!";
    $.webview.evalJS('foo(\'' + data + '\')');
});

Try with this. It should work in this case.

Upvotes: 1

Related Questions