Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8013] iOS: WebView: beforeload event fires twice if URL is valid

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionCannot Reproduce
Resolution Date2017-06-19T20:47:18.000+0000
Affected Version/sRelease 2.0.0, Release 1.8.2, Release 3.1.0
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterDustin Hyde
AssigneeEric Merriman
Created2012-03-14T14:36:42.000+0000
Updated2017-10-24T11:23:29.000+0000

Description

WebView beforeload event is fired twice if a valid URL is loaded. An invalid url will only fire the beforeload event once (as expected). Works correctly on Android (one beforeload event is fired when a valid URL is loaded). Steps to Reproduce: 1. Run code, press 'Open Google'.
var win = Ti.UI.createWindow({
	backgroundColor:'blue'
});

var buttonGoogle = Ti.UI.createButton({
	title:'Open Google',
	top:'20%',
	height:'30%',
	left:'10%',
	right:'10%'
});

buttonGoogle.addEventListener('click', function(){
	var webView = Ti.UI.createWebView({
			url:'http://www.google.com'
		});
	
	webView.addEventListener('load', function(){
		alert('load: ' + webView.url);
		});
	
	webView.addEventListener('beforeload', function(){
		alert('beforeload: ' + webView.url);
		});
		
	webView.addEventListener('error', function(){
		alert('error: ' + webView.url);
		});
		
	win.add(webView);
	
	var button = Ti.UI.createButton({
		title:'Close',
		right:0,
		bottom:0,
		height:'10%',
		width:'20%'
	});
	
	button.addEventListener('click', function(){
		win.remove(webView);
	});
	
	webView.add(button);
});

win.add(buttonGoogle);

var buttonInvalid = Ti.UI.createButton({
	title:'Open Invalid URL',
	bottom:'20%',
	height:'30%',
	left:'10%',
	right:'10%'
});

buttonInvalid.addEventListener('click', function(){
	var webView = Ti.UI.createWebView({
			url:'http://xxx'
		});
	
	webView.addEventListener('load', function(){
		alert('load: ' + webView.url);
		});
	
	webView.addEventListener('beforeload', function(){
		alert('beforeload: ' + webView.url);
		});
		
	webView.addEventListener('error', function(){
		alert('error: ' + webView.url);
		});
		
	win.add(webView);
	
	var button = Ti.UI.createButton({
		title:'Close',
		right:0,
		bottom:0,
		height:'10%',
		width:'20%'
	});
	
	button.addEventListener('click', function(){
		win.remove(webView);
	});
	
	webView.add(button);
});

win.add(buttonInvalid);

win.open();
Expected Result: Only one beforeload event should fire. Actual Result: Two beforeload events fire.

Comments

  1. Shameer Jan 2013-04-04

    Issue reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 Titanium SDK version: 3.0.2 iOS iPhone Simulator: iOS SDK version: 6.0
  2. Lee Morris 2017-06-19

    I am unable to reproduce this issue with the following environment; iPhone 7 (10.2) Studio 4.9.0.201705302345 Ti SDK 6.1.1.v20170609091155 Appc NPM 4.2.9 Appc CLI 6.2.1 Ti CLI 5.0.13 Alloy 1.9.11 Arrow 2.0.0 Xcode 8.2 (8C38) Node v4.8.2 Java 1.8.0_131

JSON Source