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?
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 thisfunction 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
-
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. -
Could you share that js with me?
-
Thanks, that gives a couple of ideas
-
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.