Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14849] iOS: JavaScript click event is not registered when parent webview's click event is also handled

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2013-08-13T17:35:04.000+0000
Affected Version/sRelease 3.1.2
Fix Version/s2013 Sprint 17, 2013 Sprint 17 API
ComponentsiOS
Labelsqe-3.1.2
ReporterAnshu Mittal
AssigneeIngo Muschenetz
Created2013-08-13T10:32:19.000+0000
Updated2017-03-03T22:04:33.000+0000

Description

Javascript click event is not registered when parent webview's click event is also handled. This is not regression since the issue occurs on 3.1.1 GA as well. Steps to reproduce: 1. Create an app using the code below. 2. Launch the app. 3. Click on 'click me' label. Expected: Alert should appear on screen with message "123456" Actual: No alert appears with the above message.
var _window = Titanium.UI.createWindow({  
    
    backgroundColor:'#fff'
});
_window.backgroundColor = 'yellow'

	_window.addEventListener('click', function(e) {
		alert('Window clicked');
	});
	var webView = Titanium.UI.createWebView({
		top : 30
	});
	var html = '<html>' + '<body>' + '<br />' + '<br />' + '<br />' + '<br />' + '<br />' + '<br />' + '<a onclick="javascript:alert(123456)">Click me!</a>' + '</body>' + '</html>';
	webView.html = html;
	webView.addEventListener('click', function(e) {
		alert('WebView Clicked');
	});
	_window.add(webView);
        _window.open();

Comments

  1. Sabil Rahim 2013-08-13

    Webview has a property [webview.willHandleTouches](http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.WebView-property-willHandleTouches) do with this exact issue. On iOS we can choose to either handle all the events inside the html itself or have the webview and its parent have and not both at the same time. By setting this property to false, the alert 123456 will be fired properly. Refer documentation for more infromation. Test with following code same to get the correct behavior.
       var _window = Titanium.UI.createWindow({  
       	backgroundColor:'#fff'
       });
       _window.backgroundColor = 'yellow'
       
       _window.addEventListener('click', function(e) {
       	alert('Window clicked');
       });
       var webView = Titanium.UI.createWebView({
       	top : 30
       });
       var html = '<html>' + '<body>' + '<br />' + '<br />' + '<br />' + '<br />' + '<br />' + '<br />' + '<a onclick="javascript:alert(123456)">Click me!</a>' + '</body>' + '</html>';
       webView.html = html;
       webView.willHandleTouches = false;
       webView.addEventListener('click', function(e) {
       	alert('WebView Clicked');
       });
       _window.add(webView);
       _window.open();
       
       
    Marking ticket as invalid.
  2. Eric Merriman 2017-03-03

    Closing as invalid.

JSON Source