Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked April 30th 2010 by Gabriel Cox
  • evaljs
  • evaljs()
  • webview
0 Comments

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] );
        }
    });
    
    — answered November 16th 2010 by Aaron Saunders
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.