Titanium Community Questions & Answer Archive

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

Access local files in webview via fileURLWithPath

With the iphone sdk you can access local files inside a webview using fileURLWithPath. What is the equivalent in the API if any?

— asked March 17th 2010 by Laney Dale
  • iphone
  • webview
0 Comments

4 Answers

  • Just use the 'url' property when constructing a webView.

    If a file 'local_web.html' is in your Resources folder, you could simply use:

                var webview = Titanium.UI.createWebView({
                    url:'local_web.html',
                    height:'auto',
                    width:300,
                    borderWidth:1,
                    top:10,
                    borderColor:'#eee'
                });
    
    — answered March 17th 2010 by Kosso
    permalink
    0 Comments
  • I get that. what I mean is that the webview opens a page and that page has images. Thos images are referenced now as /images/pic.jpg , etc. With those images living on the web server. I wan to load those in the app and then have the webview retrieve them from the app instead of the server.

    — answered March 17th 2010 by Laney Dale
    permalink
    0 Comments
  • OK. You could download the images from your webserver to your app data directory then reference them there in your local webview html.

    Get your app to create a folder called 'images' and then download them to there.

    With a bit of string.replace and regex work you should be able to then alter the html to whatever you want.

    Is that what you mean?

    — answered March 17th 2010 by Kosso
    permalink
    0 Comments
  • no, not exactly. THe html is on the server and the images are not.

    — answered March 18th 2010 by Laney Dale
    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.