I've been having problems left and right with Titanium's webview... Require serious assistance ASAP.
I'm using Alloy. What I'm trying to do is to change the URL of a webview that I've previously created in alloy.js
My alloy.js file first creates a webview:
Alloy.Globals.webview = Titanium.UI.createWebView(); Alloy.Globals.setUserAgent(); //function that just sets the user agent Alloy.Globals.webview.url = "http://www.google.ca";Then on index.js, I have a button where when I click it, it creates my controller: "web" and opens it:
var win = $.index; button.addEventListener('click',function(e) { var theTest = Alloy.createController('web').getView(); theTest.open(); win.close(); });On web.js, I add the webview to a view:
$.view_webview.add(Alloy.Globals.webview);Still on web.js, I have another view where when I click on it, it tries to change the url of this webview:
view_getpoints.addEventListener('click', function(e){ $.Alloy.Globals.webview.url = "http://www.youtube.com"; });This didn't work, the webview's url was still at google for some reason. So I tried this:
view_getpoints.addEventListener('click', function(e){ $.Alloy.Globals.webview.setUrl("http://www.youtube.com"); });That didn't work either, same result, was still at google.
I then figured I probably need to do it directly to the webview I added rather than to the variable. So I went to output the child of the view I added the webview to just to see if I can get the webview:
view_getpoints.addEventListener('click', function(e){ Ti.API.info("child: " + $.view_webview.getChildren(0)); }Sure enough, it outputs: "child: [object WebView]". All great right? No! Despite the fact that I've clearly managed to gain access to the WebView, doing something such as:
view_getpoints.addEventListener('click', function(e){ $.view_webview.getChildren(0).url = "http://www.youtube.com"; }Outputs an error saying "url" is undefined. What? This is a WebView. According to the docs: http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.WebView-property-url
The WebView object has a url field!
Well doing that didn't work as it gave an error. So I tried setUrl() to that child:
$.view_webview.getChildren(0).setUrl("http://www.youtube.com");Says "setUrl" is undefined. ..H..How?? How could it be undefined when I literally just debugged it and it told me that $.view_webview.getChildren(0) is indeed a WebView Object ??
Help.