Miyao
Miyao

Reputation: 43

Send data to external webview

I'm trying to send some data from app.js to an open webview (external url, example: 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.

Upvotes: 1

Views: 2021

Answers (2)

Hunter D
Hunter D

Reputation: 673

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.

Upvotes: 1

Miyao
Miyao

Reputation: 43

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>

Upvotes: 2

Related Questions