Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked July 13th 2010 by Connor Zwick
  • html
  • local
  • webview
0 Comments

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.

    — answered July 14th 2010 by null null
    permalink
    1 Comment
    • It worked ! Thanks

      — commented March 3rd 2014 by Ishara Amarasekera
  • 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!

    — answered July 14th 2010 by Connor Zwick
    permalink
    0 Comments
  • 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.

    — answered July 13th 2010 by Felipe Apostol
    permalink
    0 Comments
  • 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.

    — answered July 13th 2010 by Connor Zwick
    permalink
    0 Comments
  • CZ, the Kitchen Sink app has several examples of opening HTML files both locally and remotely.

    — answered July 13th 2010 by null null
    permalink
    0 Comments
  • 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?

    — answered July 13th 2010 by Connor Zwick
    permalink
    0 Comments
  • 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.

    — answered July 14th 2010 by Zachary Johnson
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.