Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Passing variable from titanium js class to html script ?

HI! I need to pass the parameter of titanium js files to the html scripting function , then which is used to load into the corresponding webview url of titanium.

Any provide guidelines for it please. I tried with evalJS in android but it is not working.

My sample Titanium test.js code is…….

var webview = Titanium.UI.createWebView({
    url:'web.html',
    height:400,
    width:320,
    top:0,left:0


});
var a=3;
var b=5;
webview.evalJS('test(a,b);');

Then i need to invoke the function in html script of web.html file,

<!DOCTYPE html>
<html><head>
<script type="text/javascript"   src="test.js"></script>
 <script type="text/javascript">
function test(a,b)
  {
      alert("returning value : " + (a+b));

  }

</script></head><body>
Hello</body>
</html>
— asked October 25th 2010 by Karthikeyan Chandran
  • android
  • iphone
  • parameterpassing
  • webview
0 Comments

1 Answer

  • you need to wrap you evaljs in an event to make sure the webView has loaded the page before attempting to execute

    
    webView.addEventListener('load',function(e)
    {
        webview.evalJS('test(a,b);');
    });
    
    — answered November 16th 2010 by Aaron Saunders
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.