Recieving error unexpected token var when calling evalJS
var downloadswebview = Ti.UI.createWebView(); downloadswebview.scalesPageToFit = false; downloadswebview.addEventListener('load',function(e) { downloadswebview.evalJS( "var links = document.getElementsByName('downloadlink');for (link in links){links[link].setAttribute('onclick','totifromwebview(this.href)')}function totifromwebview( clickedurl ){ Ti.App.fireEvent('detailWebview', clickedurl ); }" ) }); Ti.App.addEventListener('detailWebview', function(e) { alert('Link clicked!'); Ti.API.info(e.value);});
3 Answers
before calling "evalJS", you need to load some html into the webview and call evalJS inside "load" event of the webview.
html is irrelevant, can be something like this:
<html> <body /> </html>
can you post a complete code fragment to avoid further "peace-meal"ing?
one general observation:
never use "global" variables in your event handlers (one of the titanium best practices "must not to" things).
in your code, inside "load" handler, try to change downloadswebview.evalJS(...) to e.source.evalJS(...)
Your Answer
Think you can help? Login to answer this question!