How can i hide a webview when the url gets a 404 error?
Title says it all id really appreciate a code example willing to pay some money if the solution works.
6 Answers
-
Accepted Answer
Hi, here's a working example:
var wv = Ti.UI.createWebView({ url:'http://developer.appcelerator.com/questionsdfd/130976' }); var xhr = Ti.Network.createHTTPClient(); xhr.onload = foo; xhr.open('GET', 'http://developer.appcelerator.com/questionsdfd/130976'); xhr.send(); var win = Ti.UI.createWindow({ title:'Tab 1', backgroundColor:'#fff' }); win.add(wv); win.open(); function foo() { if (this.status == 404) { alert('Got 404 error - WebView will be hidden.'); wv.hide(); } };
-
You could use an HTTPclient call to check for the existence of the page before displaying the web view. You are looking for the status value specifically.
-
Can you give me a working example please im struggling.
-
you could listen the webview
load
event and look thewebview.html
property for "Error 404" string on title. Not 100% valid, but can do the job in most cases. -
I figured a workaround but thanks for all your help
-
Essentially i wanted to use this method to point to a page that tells you if the app is up to date so instead of using titanium i did it via the website. Implementing page redirect code which i can switch off and thus the page that shows the update message will be displayed. So not used titanium at all but i have managed to get exactly what i wanted.