Titanium Community Questions & Answer Archive

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

Webview DOM

I need to access the DOM for a webview from within titanium, the closest I have been able to do is use the HTML property to read the contents, but I need full DOM access to the webview contents.

Is there any way to do this?

— asked April 1st 2010 by JT Jankowiak
  • dom
  • mobilesdk
  • webview
0 Comments

5 Answers

  • there is a js file, header.js that is included into the html like any other js file
    one function contained by header.js is this

    
    function set_scroll() {
        Titanium.App.fireEvent('set_scroll',{
            scroll_position:(window.pageYOffset/document.body.offsetHeight)
            });
    
    }
    

    and is triggered by touchend event on document.body

    in app.js I have this:

    
    Titanium.App.addEventListener('set_scroll', function(data) {
        Titanium.App.Properties.setDouble('sp', data.scroll_position );
        scroll_position =  data.scroll_position;
    });
    

    in my case this is the dom talking to titanium, but you can make it at reverse, ading in header.js the events , and trigger it from titanium.

    It is working

    — answered April 1st 2010 by Dan Tamas
    permalink
    0 Comments
  • I made a js file that I include it in the html code , and it acts like a proxy for titanium using events.
    I only use if for some scroll stuff, but I think it can be easy extended.

    — answered April 1st 2010 by Dan Tamas
    permalink
    0 Comments
  • Could you share that js with me?

    — answered April 1st 2010 by JT Jankowiak
    permalink
    0 Comments
  • Thanks, that gives a couple of ideas

    — answered April 1st 2010 by JT Jankowiak
    permalink
    0 Comments
  • since you are locally I think you can use safely eval, so the triggered event in header.js can simply evaluate the js sent by Titanium.
    so you can sent to the webview the script that evaluated will access the dom.

    — answered April 1st 2010 by Dan Tamas
    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.