Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3539] Android: No Ti Javascript injection to webview

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionInvalid
Resolution Date2011-07-07T11:15:55.000+0000
Affected Version/sRelease 1.6.0
Fix Version/sSprint 2011-25
ComponentsAndroid
Labelsandroid
ReporterKT
AssigneeDon Thorp
Created2011-04-15T03:46:27.000+0000
Updated2011-07-07T11:15:55.000+0000

Description

evalJS() doesn't work, period, on Android 2.2, but seems to on 1.6 and 3.0.

However, communicating back from the webview to the application doesn't work because there doesn't seem to be a similar mechanism in place as there is on iOS to inject the necessary Javascript at the head of the HTML, resulting in errors like:

E/Web Console( 504): ReferenceError: Can't find variable: Ti at file: ...

when trying to do something like Ti.App.fireEvent().

For reference: http://developer.appcelerator.com/question/118231/ti-injection-for-webview-failing-on-android"> http://developer.appcelerator.com/question/118231/ti-injection-for-webview-failing-on-android

Comments

  1. Paul Dowsett 2011-06-18

    The following code demonstrates that Titanium now works as expected:
       var win = Ti.UI.createWindow({
       	backgroundColor : "blue",
       	exitOnClose:true
       });
       
       var view = Ti.UI.createWebView({
       	scalesPageToFit: false,
       	url:'myweb.htm'
       });
       view.addEventListener('load', function() {
       	Ti.API.info("************TITLE: " + view.evalJS("document.title"));
       	Ti.API.info("************CONTENT: " + view.evalJS('document.getElementsByTagName("html")[0].innerHTML'));
       });
       win.add(view);
       win.open();
       
       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">
       <head>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
       <title>This is the title</title>
       </head>
       <body>
       <div id="page-content">
       	<h1>Testing Titanium</h1>
       	<div id="inner-content">
       	<p>This is the content</p>
       	</div>
       </div>
       </body>
       </html>
       
  2. Paul Dowsett 2011-06-18

    Note this ticket is duplicated in TIMOB-3554
  3. Don Thorp 2011-07-07

    Closing as invalid per Paul's comment.

JSON Source