Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9593] Android: Webview: Webview with HTML property having HTML content does not reload

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-07-26T10:32:11.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sRelease 3.1.0, 2013 Sprint 02 API, 2013 Sprint 02, 2013 Sprint 05 API, 2013 Sprint 05
ComponentsAndroid
Labelsapi, module_webview, qe-and060112, qe-testadded, regression
ReporterSatyam Sekhri
AssigneeVishal Duggal
Created2012-06-17T01:48:06.000+0000
Updated2014-03-27T10:54:59.000+0000

Description

A webview with HTML property (containing the HTML content of the webview) loads successfully but does not reload. The behavior occurs since 2.0.1. This worked fine on 1.8.2 Steps to reproduce: 1. Create an application with code below 2. Launch app on android device 3. Click on "Remove and release and add webview" button Actual: After step 2, the webview launches successfully After step 3, the webview does not reload Expected: The webview with HTML content should reload.
var _window = Ti.UI.createWindow({
	backgroundColor:'#000'
})
 		var webview=Ti.UI.createWebView({
			//url:'http://www.google.com',
			html:'<html><body>test</body></html>',
			top : 0,
			height : 200
		});
		
		webview.addEventListener('load', function() {
			alert('The webview is loaded!');
		});

		var b2 = Ti.UI.createButton({
			title : "remove and release and add webview",
			top : 280
		});
		b2.addEventListener("click", function() {
			_window.remove(webview);
			webview.reload();
			_window.add(webview);
		});

_window.add(webview);
_window.add(b2);
_window.open();

Attachments

FileDateSize
app.js2013-02-26T23:02:05.000+00002809
test.html2013-02-26T23:02:05.000+0000173
test2.html2013-02-26T23:02:05.000+0000171
webview.html2013-02-26T23:02:05.000+0000192

Comments

  1. Neeraj Gupta 2012-06-17

  2. Satyam Sekhri 2012-12-21

    The issue still occurs. Tested on 3.0.0.GA. The issue is same as TIMOB-3501 which was reported for both url and html property of webview. However the url property works fine now and the issue exists only for html property.
  3. Vishal Duggal 2013-01-25

    Pull pending https://github.com/appcelerator/titanium_mobile/pull/3782
  4. Ping Wang 2013-01-25

    Another test case: Put flower.jpg in /Resources/ .
       var _window = Ti.UI.createWindow({
       	backgroundColor : '#000'
       })
       
       var html = '<html><img src="flower.jpg" alt="flower" height="100" width="100"></html>';
       
       var webview = Ti.UI.createWebView({
       	html: html,
       	top : 0,
       	height : 200
       });
       
       webview.addEventListener('load', function() {
       	alert('The webview is loaded!');
       });
       
       var b2 = Ti.UI.createButton({
       	title : "remove and release and add webview",
       	top : 280
       });
       b2.addEventListener("click", function() {
       	_window.remove(webview);
       	webview.reload();
       	_window.add(webview);
       });
       
       _window.add(webview);
       _window.add(b2);
       _window.open(); 
       
  5. Vishal Duggal 2013-01-25

    Bad test case. If this code is in base Resources/ folder it might work. What if this code is in a file that is in a subfolder of Resources?
  6. Vishal Duggal 2013-01-28

    Backport PR https://github.com/appcelerator/titanium_mobile/pull/3805
  7. Shyam Bhadauria 2013-01-29

    Webview is reloading successfully now. Titanium SDK: 3.1.0.v20130128172329 Titanium SDK: 3.0.2.v20130128174806 Titanium  Studio:3.0.2.201301251115 Device: Samung GALAXY Tab 620 Android 3.2, Samsung GALAXY Note Android 2.3.6
  8. Ingo Muschenetz 2013-02-13

    The fix for this resulted in a slight change with regards to needing a base URL: Formerly:
       var win = Titanium.UI.createWindow({
       backgroundColor:'#fff'
       });
       
       win.add(Titanium.UI.createWebView({
       height:Ti.UI.FILL,
       width:Ti.UI.FILL,
       html:"<html><script src='hello.js'></script><body><p>hello</p></body></html>"
       }));
       
       win.open();
       
    Now, the behavior is like so (note the addition of baseURL):
       var win = Titanium.UI.createWindow({
       backgroundColor:'#fff'
       });
       
       var webview = Titanium.UI.createWebView({
       height:Ti.UI.FILL,
       width:Ti.UI.FILL
       });
       
       win.add(webview);
       webview.setHtml("<html><script src='hello.js'></script><body><p>hello</p></body></html>", {baseURL:'file:///android_asset/Resources/'});
       win.open();
       
  9. Nathan Nadeau 2013-02-21

    I think Ping Wang's test case with flower.jpg is a valid test case because the documentation for WebView at http://docs.appcelerator.com/titanium/3.0/#!/guide/The_WebView_Component-section-29004918_TheWebViewComponent-UsingLocalWebContentwithWebView declares that "all local web content is available relative to your project's Resources directory" as below: bq.Let's say you not only want to show a local HTML file, but you also want that HTML file to have access to local CSS and Javascript files. All you need to do is remember that all local web content is available relative to your project's Resources directory. You can think of Resources almost as a local web server root path. To illustrate this point, let's take the prior example and expand it to use local CSS and Javascript files. So many developers are going to expect the the URLs for any local resource files will be relative to the Resources directory by default. Having to add a special {baseURL:'file:///android_asset/Resources/'} for Android breaks that supposed rule. Having to use a baseURL option is fine but it should be clarified in the documentation or some other appropriate location because this will break existing code that used the assumption from the documentation that all local resources are relative to your Resources directory of your project. For example my project worked great until 3.0.2, at which point none of my local Android resource files were being loaded correctly until I came across this workaround.
  10. Azwan b. Amit 2013-02-26

    What is the supposed value for baseURL above for iOS? this breaking change cause my app to stop working until I found this bug report. Also, even with baseURL specified, I couldn't fireEvent to and from webview and js module.
  11. Nathan Nadeau 2013-02-26

    @Azwan this bug is only for Android, so you only need to set the baseURL for Android. In my app, for iOS, I simply don't specify any baseURL and the files load correctly, as expected. I cannot verify your problems with firing events to and from the webview and the local js; for me it all works fine in both Android and iOS once I've set the baseURL for Android. I fire an event from the local JS loaded by the webview component, and I can receive that event in my application code. I have not yet tried firing an event from my Titanium code and receiving it in the local webview component.
  12. Vishal Duggal 2013-02-26

    Reopening to fix the reload method and fix the baseURL problems
  13. Vishal Duggal 2013-02-26

    Resources for test case
  14. Vishal Duggal 2013-02-26

    PR https://github.com/appcelerator/titanium_mobile/pull/3909
  15. Shyam Bhadauria 2013-03-12

    Environment used for verification - Titanium SDK: 3.1.0.v20130311192922 Titanium  Studio:3.0.2.201302151605 Device: Samsung GALAXY Note (2.3.6) and Samung GALAXY Tab 620 Android 3.2
  16. Priya Agarwal 2013-07-26

    Reopening to update label.
  17. Priya Agarwal 2013-07-26

    updated label. Closing as Fixed. Verified with environment: Studio: 3.1.1.201306131423 SDK: 3.1.2.v20130725180746 acs:1.0.3 alloy:1.1.3 npm:1.2.14 titanium:3.1.1 titanium-code-processor:1.0.1 OS: OSX 10.8 Device: HTC Desire(v4.0.3),iphone simulator(v6.0) Webview with HTML property having HTML content getting reload now.
  18. Fokke Zandbergen 2014-03-27

JSON Source