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.
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:
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:
Resolving as invalid.
Closing ticket as invalid.