Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (android)
Viewing all articles
Browse latest Browse all 7655

How to load a local javascript file in webview?

$
0
0

I've been playing around with WebViews, and I seem to be having trouble loading a javascript file from the Resources directory, while loading from remote sources via http works fine.

Currently testing on Android emulator, do not have access to iPhone emulator for testing.

Files arranged as follows:

Resources/html/loadtest.html

Resources/test/test.jsf

Creating the webview:

var self = Ti.UI.createWindow({
    title:'The Title',
    exitOnClose:true,
    navBarHidden:false
});
 
var webview = Ti.UI.createWebView({
    top: 0,
    url: 'app://html/loadtest.html'
});
loadtest.html:
<html>
    <head>
        <title>The Title</title>
        <!-- THIS WORKS -->
        <script type="text/javascript" src="http://mywebsite.com/test.jsf"></script> 
        <!-- NONE OF THESE WORK
        <script type="text/javascript" src="../test/test.jsf"></script>             
        <script type="text/javascript" src="app://test/test.jsf"></script>
        <script type="text/jscript" src="app://Resources/test/test.jsf"></script>
        -->
    </head>
    <body>
        <div id="chart_div" style="width: 900px; height: 500px;"></div>
    </body>
</html>
Loading from a remote source, e.g. "http://mywebsite.com/test.jsf" will load the script fine, but I can't seem to figure out how to load it from the Resources directory.

In the KitchenSink example "local_webview.html", they use a relative source, e.g. "../jquery-1.3.2.js", but that doesn't work here. And neither does using "app://test/test.jsf" or "app://Resources/test/test.jsf".

What is the proper way to do this?


Viewing all articles
Browse latest Browse all 7655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>