What does webview.evalJS() return?
The documentation says this:
invoke JavaScript inside the context of the webview and optionally, return a result
I would actually like to get something back, but I'm not sure how. I tried a function call with a "return", It ran, but the result did not get returned. I guess that makes sense. In most languages I guess something like eval() would return <stdout>? If that is the case here, how would I write to stdout from javascript in a webview?
1 Answer
-
I was stumped for a while and then I realized I needed to do it in an event to ensure the window was loaded. BTW this was in an iPhone
var webView = Ti.UI.createWebView({url:"http://www.google.com"}); win1.add(webView); webView.addEventListener('load',function(e) { var cookies = webView.evalJS("document.cookie").split(";"); Ti.API.info( "# of cookies -> " + cookies.length ); for (i = 0; i <= cookies.length - 1; i++) { Ti.API.info( "cookie -> " + cookies[i] ); } });