Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16648] BB: Ti is not defined when a WebView is created with a remote url

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2014-03-20T16:45:18.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsBlackBerry
Labelsn/a
ReporterDavide Cassenti
AssigneePedro Enrique
Created2014-03-20T12:41:45.000+0000
Updated2017-03-14T21:08:03.000+0000

Description

Description of the problem

In BB10, when a WebView is created with a remote URL, Ti does not seem to be defined. Thus, you cannot perform calls like Ti.App.fireEvent.

Steps to reproduce

Use this code
var win = Ti.UI.createWindow({
	backgroundColor:'white'
});

var webview = Ti.UI.createWebView({
	url : 'http://www.example.com'
});

Ti.App.addEventListener('geturl', function(e) {
	alert('url: ' + e.url); // the url is defined
});

webview.addEventListener('load', function() {
	setTimeout(function() {
		webview.evalJS('Ti.App.fireEvent("geturl", { "url": window.location.href })');
	}, 1000);
});

win.add(webview);
win.open();

Additional notes

By changing the 'url' property to a local file, Ti is defined, e.g.:
var webview = Ti.UI.createWebView({
	url : 'test.html'
});
Also note that, even with local files Ti does not seem to be defined *unless* I add a timeout.

Comments

  1. Davide Cassenti 2014-03-20

    One additional comment here. I noticed that this code works if I first load a local page, and then change the URL to a remote one:
       var win = Ti.UI.createWindow({
           backgroundColor:'white'
       });
        
       var webview = Ti.UI.createWebView({
           url : 'test.html'
       });
       webview.url = 'http://www.example.com';
        
       Ti.App.addEventListener('geturl', function(e) {
           alert('url: ' + e.url); // the url is defined
       });
        
       webview.addEventListener('load', function() {
           setTimeout(function() {
               webview.evalJS('Ti.App.fireEvent("geturl", { "url": window.location.href })');
           }, 1000);
       });
        
       win.add(webview);
       win.open();
       
  2. Pedro Enrique 2014-03-20

    The Ti namespace is not defined in a remote url WebView, this is expected behavior. I tested the same code in iOS and the event to get the url never fires. I placed an extra alert verify that the evalJS is getting called. Sample code with one more alert:
       var win = Ti.UI.createWindow({
           backgroundColor:'white'
       });
        
       var webview = Ti.UI.createWebView({
           url : 'http://www.example.com'
       });
        
       Ti.App.addEventListener('geturl', function(e) {
           alert('url: ' + e.url); // the url is defined
       });
        
       webview.addEventListener('load', function() {
           setTimeout(function() {
           	alert('calling evalJS');
               webview.evalJS('Ti.App.fireEvent("geturl", { "url": window.location.href })');
           }, 1000);
       });
        
       win.add(webview);
       win.open();
       
    Resolving as invalid.
  3. Lee Morris 2017-03-14

    Closing ticket as invalid.

JSON Source