{ "id": "62411", "key": "TIMOB-1779", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "2", "description": "The problem described is an issue which will never be fixed.", "name": "Won't Fix" }, "resolutiondate": "2017-08-08T18:48:13.000+0000", "created": "2011-04-15T03:02:02.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "api" ], "versions": [ { "id": "13505", "description": "Release 3.0.0", "name": "Release 3.0.0", "archived": true, "released": true, "releaseDate": "2012-12-14" } ], "issuelinks": [], "assignee": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2017-08-08T18:48:13.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "{html}

Problem

\r\n

When a web view on Android navigates to an external URL, the\r\n\"html\" property becomes unusable -- you cannot get or set its\r\nvalue. If you set the \"html\" property, then navigate to an external\r\nURL, setting the \"html\" property has no effect on the web view. And\r\nreading the \"html\" property reflects what you originally set it as\r\nbefore navigating to the external URL.

\r\n

Failcase

\r\n

The following code demonstrates setting the \"html\" property,\r\nwith a link to an external site.

\r\n
\r\nvar win = Titanium.UI.createWindow({\r\n    backgroundColor:'#fff'\r\n});\r\n\r\nvar html1 = '<html><body><a href=\"http://www.google.com\">Google</a></body></html>';\r\nvar html2 = '<html><body><a href=\"http://www.yahoo.com\">Yahoo</a></body></html>';\r\n\r\nvar wv = Ti.UI.createWebView({html: html1, backgroundColor: 'yellow', top: 50});\r\nwin.add(wv);\r\n\r\nvar btn = Ti.UI.createButton({\r\n    title: 'Set HTML', top: 10, height: 40, width: 100, left: 10\r\n});\r\nbtn.addEventListener('click', function() {\r\n    alert(wv.html);\r\n    wv.html = html2;\r\n});\r\nwin.add(btn);\r\n\r\nwin.open();\r\n
\r\n

Steps to Reproduce with Failcase

\r\n
    \r\n
  1. Start off by clicking \"Set HTML\", and it will alert \"web.html\"\r\nfor you to see; the web view will update to contain a link to\r\nYahoo. So far so good.
  2. \r\n
  3. Click the link to Yahoo,
  4. \r\n
  5. Then click \"Set HTML\" again, and the web view will not update.\r\nAlso, the alerted html will be from what you previously set.
  6. \r\n
\r\n

If you run this same code on iOS, you'll see Yahoo's HTML\r\nalerted, and then the web view will properly update to be the html\r\nyou specified.

\r\n

Expected Results

\r\n

A new page shows with just one link (to yahoo this time.)

\r\n

Workaround

\r\n

Two workarounds are required, but both are rather simple:

\r\n

To get around the setting-doesn't-update issue, first set the\r\nurl property of the web view to an empty string. In the failcase,\r\nthis would look like this:

\r\n
\r\nbtn.addEventListener('click', function() {\r\n    alert(wv.html);\r\n    wv.url = '';\r\n    wv.html = html2;\r\n});\r\n
\r\n

Now getting around the reading-html-returns-stale-html issue is\r\na bit more difficult. We need to run some JavaScript to do so. This\r\nisn't entirely foolproof, but it should give you a fairly accurate\r\ndump of the HTML after the page loads:

\r\n
\r\nbtn.addEventListener('click', function() {\r\n    var response = '<html>' + web.evalJS('document.getElementsByTagName(\"html\")[0].innerHTML') + '</html>';\r\n    alert(response);\r\n    wv.url = '';\r\n    wv.html = html2;\r\n});\r\n
\r\n

Tested On

\r\n

Titanium SDK version: 1.6.0 (02/23/11 12:34 9882e81)
\r\nBROKEN on Android Emulator 2.2 APIs
\r\nBROKEN on Android Device Epic 4G 2.2
\r\nWORKS on iPhone Simulator 4.2

\r\n

Associated Helpdesk Ticket

\r\n

http://developer.appcelerator.com/helpdesk/view/76225

{html}", "attachment": [], "flagged": false, "summary": "Android: Cannot set Webview's html property after navigating somewhere", "creator": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "environment": null, "comment": { "comments": [ { "id": "126645", "author": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "body": "{html}

I'm seeing the same behavior on the other side of things --\ngetting the HTML, as opposed to setting it. I'll update the\noriginal ticket with additional details.

{html}", "updateAuthor": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "created": "2011-04-15T03:02:04.000+0000", "updated": "2011-04-15T03:02:04.000+0000" }, { "id": "214818", "author": { "name": "jyounus", "key": "jyounus", "displayName": "Junaid Younus", "active": true, "timeZone": "Europe/London" }, "body": "Tested using TiSDK 2.2.0v20120816015712 on a Samsung Galaxy S2, issue still valid.", "updateAuthor": { "name": "jyounus", "key": "jyounus", "displayName": "Junaid Younus", "active": true, "timeZone": "Europe/London" }, "created": "2012-08-16T11:47:48.000+0000", "updated": "2012-08-16T11:47:48.000+0000" }, { "id": "426208", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing due to inactivity. If this issue still exists, please raise a new ticket.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-08-08T18:48:13.000+0000", "updated": "2017-08-08T18:48:13.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }