Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-974

Android: Webview.html returns null if webview is based on URL

    Details

      Description

      Problem

      The html property of a web view returns undefined for remote URLs.

      Sample Code

      The following will test if the html property is convincingly set for a reliable remote URL (the server always returns the text "GET"). If it is, a green border will show up. If it fails, a red border will show up.

      app.js

      /**
       * This tests sees if the Ti.UI.WebView will properly return the HTML of a remote website.
       * (And it gets ornery if it fails to grab the HTML.)
       */
      var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
      var web = Ti.UI.createWebView({
          url: 'http://appc.me/test/Echo',
          width: '90%', height: '90%', top: '5%', left: '5%'
      });
      win.add(web);
      win.open();
      web.addEventListener('load', function() {
          // The server returns just 'GET', but iOS forces the web view to be well formed...
          Ti.API.info(web.html);
          // So we'll accept either a well formed HTML or the literal response from the server.
          if (web.html == '<html><head></head><body>GET</body></html>' || web.html == 'GET') {
              win.backgroundColor = '#0f0';
              alert('PASS: I love you forever!');
          }
          // Otherwise... FAIL!
          else {
              win.backgroundColor = '#f00';
              alert('FAIL: web.html != expected html');
          }
      });
      

      Associated Helpdesk Ticket

      None, but there is a Staff Augmentation project that needs this for their Android app to work.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                hpham Hieu Pham
                Reporter:
                billdawson Bill Dawson
              • Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Git Source Code