{ "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}
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\nThe 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\nIf 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\nA new page shows with just one link (to yahoo this time.)
\r\nTwo workarounds are required, but both are rather simple:
\r\nTo 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\nNow 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\nTitanium 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
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.