Loading local HTML files with WebView
Hi,
I'm trying to create an about page for my app. Since I am a web developer, I figured that it would be easier if I just load an HTML page, and could just format and style that. So I used the following:
var win = Titanium.UI.currentWindow;
var webview = Titanium.UI.createWebView({url:'about.html'});
win.add(webview);
I know I am directly linking to the file, because if I change it something else, in the console it gives me an error saying I am not actually linking to it. However, when I test my application, it just gives me a blank white screen even though I have a paragraph of text in the HTML file. I also lose the ability to drag the window up and down. However, if I load a site online like google, it works perfectly. It loads the site and I can drag the window up and down.
Does anyone know what my issue is?
Thanks
7 Answers
-
Accepted Answer
CZ, Try starting your HTMl file with a simple <HTML> tag only. You don't need the doctype info in there. I had the same problem and that's how I fixed it.
-
It doesn't have a space in it, and all I have is a body tag with a paragraph inside. I'll try adding an html tag.
Edit: That worked. For anybody that might search with the same problem. Make sure you have the HTML tag!
-
it could be your html file cannot be located. is there no error showing in the debug window? i tried it just now and load a local html file and works fine. try this in your project:
in 'app.js' :
var win = Titanium.UI.createWindow({url:'about.js'}); win.open();
and then a new js file say 'about.js' :
var win = Titanium.UI.currentWindow; var webview = Titanium.UI.createWebView({url:'about.html'}); win.add(webview);
that should load the about.html file . make sure the html file is in the same folder with about.js/app.js.
-
I appreciate that, yeah there is no error in the console. However, there is if I change the url to something else that doesn't exist like aboutj.html for example.
-
CZ, the Kitchen Sink app has several examples of opening HTML files both locally and remotely.
-
Yes, my problem is that everything in the kitchen sink is a lot higher level than I need. I simply need to link to a local url file. How do I do it like above?
I looked in the kitchensink originally, and it still does not work. Am I not doing it correctly above?
Or is there a better way of doing large bodies of text in Titanium?
-
Does your Titanium project name have a space in it? Try creating a new project named with no spaces and drag all your files into it.