Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1458] WebView doesn't keep html

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionDuplicate
Resolution Date2012-06-22T16:24:23.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
Reporterwolef
AssigneeNeeraj Gupta
Created2011-04-15T02:53:24.000+0000
Updated2017-03-09T21:29:42.000+0000

Description

If I add a local string to the html-attribute and try to get the string back, I'll only get an empty html tag.

var html = '<html><body>Text</body></html>';
var view = Titanium.UI.createWebView();
view.html = html;
alert(view.html);

Comments

  1. Dawson Toth 2011-06-01

    That code sample still will not work, but for a good reason. Setting the html is an async process, so it returns quickly. In the background, the web view is loading up your HTML and rendering it. When you inspect the html property right away, it will be whatever the web view had in it before you set the html property. In this case, it will be something like "". If you listen for the "load" event, you'll see your HTML returned. I expanded your example to show how to properly handle this:
       
       var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
       var html = '<html><head></head><body>Text</body></html>';
       var web = Ti.UI.createWebView({
           html: html,
           width: '90%', height: '90%', top: '5%', left: '5%'
       });
       win.add(web);
       win.open();
       web.addEventListener('load', function() {
           if (web.html != html) {
               win.backgroundColor = '#f00';
               alert('FAIL: web.html != original html');
           }
           else {
               win.backgroundColor = '#0f0';
               alert('PASS: I love you forever!');
           }
           Ti.API.info(web.html);
       });
       
  2. Vishal Duggal 2012-06-22

    Dup of TIMOB-8293
  3. Lee Morris 2017-03-09

    Closing ticket as duplicate.

JSON Source