Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27254] [iOS] WebView click event is not being fired

GitHub Issuen/a
TypeBug
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 8.0.2, Release 8.1.0
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterSamir Mohammed
AssigneeUnknown
Created2019-07-18T13:11:22.000+0000
Updated2019-07-18T19:16:48.000+0000

Description

Webview click event is not being fired when the parent window also has a click event. (Works fine on Android). *app.js*
	var window = Ti.UI.createWindow();

	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)"> <font size="30" color="red">This is some text!</font></a>' + '</body>' + '</html>';
	webView.html = html;
	webView.addEventListener('click', function(e) {
	  alert('WebView Clicked');
	});

	window.add(webView);
	window.open();
*Test steps*

Create a titanium application with the above test case

Run the program

Tap on "click me" label.

*Expected result* Three alerts appear on screen with messages "123456","WebView Clicked" and "Window clicked". *Actual result* Only one alert can be seen, "WebView Clicked".

Comments

  1. Vijay Singh 2019-07-18

    [~smohammed] 1. In iOS implementation is in such a way that you can show only one alert at a time. So it is showing only one alert. I have modified your test case, replaced alert with log message. Now I can see the log for window click event and WebView click event. 2. As for as event of javascript is concerned, it is limitation in iOS. If you want javascript event get fired, you have to use [willHandleTouches](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-property-willHandleTouches). See following note in doc for detail-
       iOS Platform Implementation Notes
       On the iOS platform, the native web view handles scrolling and other related touch events internally. If you add event listeners on the web view or its parent views for any of the standard touch events (touchstart, click, and so on), these events do not reach the native web view, and the user will not be able to scroll, zoom, click on links, and so on. To prevent this default behavior, set willHandleTouches to false.
       
       In other words, you can have either Titanium-style events against the web view instance, or internal JavaScript events in the DOM, but not both.
       

JSON Source