Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3157] Android: UI - webView is undefined in load event handler for WebView instance

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2011-12-26T10:12:11.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterSheshadri Mantha
AssigneePaul Dowsett
Created2011-09-01T09:40:31.000+0000
Updated2016-03-08T07:48:13.000+0000

Description

Problem

webView is undefined in load event handler for WebView instance

Test case

create a window

add webview to this window and tell this webview to use a local html file

add a load event handler to this webview

in this event handler, examine the webview.html or even the html within the source of the event object

local file has a link to a remote file; which when clicked does get loaded *BUT still no data in webview.html*

BTW: For sake of simplicity, i used an html page that i normally use for no connection and simply added a w3c link to it; in fact, network connection etc. are fine.
Ti.UI.setBackgroundColor('#000');

var win1 = Titanium.UI.createWindow({  
    title:'HTML Test',
    backgroundColor:'#fff'
});
var localUrl = 'noconn.html';
var webView = Ti.UI.createWebView({url:localUrl})
webView.addEventListener('load', onLoad);
function onLoad(evt) {
  if (webView.url.search(localUrl) >= 0) {
    Ti.API.info('LOCAL: +++++++++++++++++++++++++');
    Ti.API.info(evt.source.html);
    Ti.API.info('LOCAL: +++++++++++++++++++++++++');
    Ti.API.info(webView.html);
  }
  else {
    Ti.API.info(" !! NOT local html file -- " + webView.url);
    Ti.API.info('REMOTE: +++++++++++++++++++++++++');
    Ti.API.info(evt.source.html);
    Ti.API.info('REMOTE: +++++++++++++++++++++++++');
    Ti.API.info(webView.html);
  }	
}

win1.add(webView);
win1.open();
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>No Data Connection</title>
    <meta name="generator" content="Studio 3 http://aptana.com/">
    <meta name="author" content="healthtrio.com">
    <!-- Date: 2011-08-15 -->
    <p>Unable to raise the server due to connectivity issues.</p>
    <p>Please try back later.</p>
    <a href="http://www.w3schools.com">Go Remote!</a>
  </head>
  <body>
  </body>
</html>

D/KrollContext(  291): (kroll$1: app://app.js) [101,1458] Running evaluated script: file:///android_asset/Resources/app.js
I/TiRootActivity(  291): (main) [0,0] checkpoint, on root activity resume. context = org.appcelerator.titanium.TiContext@43e628a8
W/TiAnalyticsSvc(  291): (Thread-11) [39,39] Analytics Service Started
I/global  (  291): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
I/global  (  291): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
D/dalvikvm(  291): GC_FOR_MALLOC freed 2892 objects / 323576 bytes in 152ms
I/global  (  291): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
I/TiAnalyticsSvc(  291): (Thread-11) [1784,1823] Sending 2 analytics events.
I/ActivityManager(   60): Displayed activity com.healthtrio.test/.HtmltestActivity: 6794 ms (total 6794 ms)
I/TiAPI   (  291): (kroll$1: app://app.js) [1360,3183] LOCAL: +++++++++++++++++++++++++
I/TiAPI   (  291): (kroll$1: app://app.js) [1,3184] undefined
I/TiAPI   (  291): (kroll$1: app://app.js) [1,3185] LOCAL: +++++++++++++++++++++++++
I/TiAPI   (  291): (kroll$1: app://app.js) [1,3186] undefined
D/dalvikvm(  291): GC_FOR_MALLOC freed 5513 objects / 387224 bytes in 202ms
D/dalvikvm(  291): GC_FOR_MALLOC freed 1253 objects / 63240 bytes in 53ms
W/TiAnalyticsSvc(  291): (Thread-11) [2218,5404] Stopping Analytics Service
D/dalvikvm(  118): GC_EXPLICIT freed 703 objects / 39600 bytes in 58ms
D/dalvikvm(  291): GC_FOR_MALLOC freed 2351 objects / 144400 bytes in 139ms
I/TiAPI   (  291): (kroll$1: app://app.js) [5382,10786]  !! NOT local html file -- http://www.w3schools.com/
I/TiAPI   (  291): (kroll$1: app://app.js) [1,10787] REMOTE: +++++++++++++++++++++++++
I/TiAPI   (  291): (kroll$1: app://app.js) [1,10788] undefined
I/TiAPI   (  291): (kroll$1: app://app.js) [1,10789] REMOTE: +++++++++++++++++++++++++
I/TiAPI   (  291): (kroll$1: app://app.js) [0,10789] undefined
{quote}

Related Discussions

Q&A: http://developer.appcelerator.com/question/124990/webviewhtml-is-undefined-in-load-event-handler#answer-217881

Attachments

FileDateSize
device.PNG2011-09-01T09:40:31.000+000025908
htmltest-src.zip2011-09-01T09:40:31.000+0000748385

Comments

  1. Paul Dowsett 2011-12-26

    Sheshadri As this is a duplication of TIMOB-974, I will mark it resolved. You may reopen it if you disagree. However, also take a note of the changes I made to ensure that the ticket meets the [How to Submit a Bug Report](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report) guide (before I realised it was a duplicate). Please follow this when raising any tickets in future. Cheers
  2. Paul Dowsett 2012-02-17

    Closing due to inactivity. If this issue still exists, please raise a new ticket, including all the information in the [JIRA Ticket Checklist](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-JIRATicketChecklist) to ensure that we can escalate it quickly. Read [How to Submit a Bug Report](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report) if you have not read it before, and always start a ticket using the [JIRA Ticket Template](https://wiki.appcelerator.org/display/guides/JIRA+Ticket+Template). Thanks in advance

JSON Source