Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (webview)
Viewing all articles
Browse latest Browse all 680

Titanium WebView not firing App events from within embedded Javascript code

$
0
0

Hi all,

I am trying to get the Javascript inside my webview to recieve a variable that I set in my Titanium code. I figured the best way to do this was by using App events.

I have set up my HTML like this:

<html>
    <head>
        <title>Todo list</title>
    </head>
    <script type="text/javascript">
        Ti.App.addEventListener("web:AddTarea",function(tarea){
            var tbl= document.getElementById("tblTareas");
            tbl.innerHTML=tbl.innerHTML+"<tr><td>"+tarea.id+"</td><td>"+tarea.tarea+"</td></tr>";
 
        });
 
        function btnAdd_click()
        {
            Ti.API.info("About to fire event");
            var txt = document.getElementById("txtTarea");
            Ti.App.fireEvent('app:newTarea',{nombre:txt.value});
        }
    </script>
    <body>
        <input type="text" name="txtTarea">
        <input type="button" name="btnAdd" value="Añade Tarea" onclick="btnAdd_click();">
        <table id="tblTareas">
            <tr><td>ID</td><td>TAREA</td></tr>
        </table>
 
    </body>
</html>
And in my view that has the webView control:
Ti.App.addEventListener('app:newTarea',function (e)
{
    Ti.API.info("Inside App Event");
    tarea={
        id:id,
        tarea:e.nombre
    };
    id=id+1;
    Ti.App.fireEvent("web:AddTarea",tarea);
});

Now, when I push the button in my web view, its event fires, but the application event 'app:newTarea' is not firing. Anyone have any idea why?


Viewing all articles
Browse latest Browse all 680

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>