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>
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);'); });