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

iOS: Setting WebView HTML contents directly fails to load local JavaScript file on device



      When I have a simple webview where I set the HTML via the Webview.html property (or alternatively by later calling Webview.setHtml() method), and the HTML string contains a reference to a local javascript file which is included under my Resources project directory, the application fails to load the local javascript file. But this only happens when installed on the target device. When run in the simulator it works as expected.

      If instead of creating the HTML dynamically and setting it via the html property or the setHtml method, I save the HTML to a local HTML file and load it via the Webview.url property, it then works as expected on both the simulator and the device, so the issue seems to be specifically related to the Webview.html property.

      Also, in Titanium SDK 3.0.0 this worked fine, but it stopped working in 3.0.2.

      To reproduce, create the following simple app.js file:


      var html="<html>" + 
               "  <head>" +
               "    <script type='text/javascript' src='localjs/local.js'></script>" +
               "  </head>" +
               "  <body>" +
               "    <div onclick='doclick();'><p>Click Me!</p></div>" +
               "  </body>" +
      var webview = Ti.UI.createWebView({
         html: html,
         top: '5%',
         left: '5%',
         right: '5%',
         height: '90%',
         willHandleTouches: false
      var win = Ti.UI.createWindow({layout: 'vertical'});

      And in localjs/local.js under Resources directory:


      function doclick(){
         Ti.API.info('in local doclick function...');
         alert('you clicked on the webview!');

      Then make sure you are using SDK 3.0.2 and run app.js.

      Expected: The app should load up the webview, and you should be able to click on the "Click Me!" text and you should see the corresponding alert() and Ti.API.info message.

      Actual: Using 3.0.2, on simulator, it works, but when you run it on the iOS device, nothing happens when you click on "Click Me!" text (no alert and no TI log message). And also while viewing the console log on the device via Xcode, you don't see the expected debug message saying that the local.js was loaded. If you revert to SDK 3.0.0 it works on the device as expected.

      Further notes: If instead of setting the Webview.html or using the Webview.setHtml() method, you save the HTML to a local file and then load that local file in the webview via Webview.url, then it seems to work in all cases. However for my purposes I need to dynamically generate HTML so it is not an ideal workaround to use static local files.


          Issue Links



              • Assignee:
                mstepanov Max Stepanov
                bigotilda Nathan Nadeau
                Vishal Duggal (Inactive)
              • Watchers:
                0 Start watching this issue


                • Created:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    Sync status:
                    Last received:
                    Last sent:

                    Git Integration