开发者

Send data to external webview

I'm trying to send some data from app.js to an open webview (external url, examp开发者_如何学编程le: http://mysite.com/file.html), without success. I've check through many questions and answers and tried different solutions with Ti.App.fireEvent and Ti.App.addEventListener without any good success. I did however find a solution that did this with a local html-file some time ago, but weren't able to recreate this for an external.

app.js

Ti.App.fireEvent('helloWorld', { data : "Hello World" );

http://mysite.com/file.html

Ti.App.addEventListener('helloWorld', function(e) 
{   
    // do something with e.data
});

doesn't seem to do anything.


Solved the problem by using evalJS app.js

web.addEventListener('load', function() {

        var data = "some data";
        web.evalJS("testJS('" + data + "')");

});

http://mysite.com/file.html

<script>
    function testJS (data) {
        alert(data);
    }
</script>


Oddly, this only works in the iPhone simulator but not in the Android simulator (1.6 API and 2.2 API). In Android, you get the dreaded "Force Close" button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜