jQuery Mobile not working in WebView when loading from file

4,290 views
Skip to first unread message

Steve Bullis

unread,
Nov 25, 2013, 4:20:45 PM11/25/13
to tas...@googlegroups.com
In short When using Javascript in a webview locally on the phone like below

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Multi-page template</title>
<link rel="stylesheet" href="jquery/jquery.mobile-1.3.2.min.css">

<script src="jquery/jquery-1.10.2.min.js"></script>

<script src="jquery/jquery.mobile-1.3.2.min.js"></script>
</head>

Javascript does  not seem to be working.  But if I move the same file to a webserver everything works fine.

I researched the issue on the forums and nothing seemed to come up.  After Researching on Google I came across this stack overflow Question which seems to be the exact same issue although it is android specific and not Tasker but I make the assumption that the Tasker Webview is also an android Webview.


The solution included is as follows

Solved it myself. Turns out from JellyBean on, the webView settings include a property to disable loading from file resources, and it is disabled by default.

Running my app from a pre-Jelly device works fine, but the two devices I was using for development were both 4.3 based.

I solved it using the following code, if anyone is interested:

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
        s.setAllowUniversalAccessFromFileURLs(true);
        s.setAllowFileAccessFromFileURLs(true);
    }

Any Help would be great.

Steve Bullis

unread,
Nov 25, 2013, 4:53:19 PM11/25/13
to tas...@googlegroups.com
Update CSS is also affected.

Here is the Test files I Used.  




index.html
scripts.js
styles.css
Task_Test.tsk.xml
Webview2.scn.xml

Pent

unread,
Nov 26, 2013, 2:35:14 AM11/26/13
to tas...@googlegroups.com
Thanks for the premade solution :-)

I'll apply it for WebView elements if the Allow Phone Access parameter is checked and always for JavaScript/JavaScriptles actions.

Will be in the first beta after the series of u versions for the latest stable release are finished (KitKat issues keep coming up)

Pent

Kurt Anderson

unread,
Mar 1, 2014, 3:55:09 PM3/1/14
to tas...@googlegroups.com
I tried Steve's example above, and it just will not work. I've poked and prodded the system, but there seems to be no way to catch a log of the webview's doings. sigh.

(I embedded everything in one file, and it worked.)

I'm running:
4.3b7
LGOG (LG E970)
CM 10.2 (jb)

Anyone have any ideas? Does CM's build disable local file access (compiler option)?

Danielo515

unread,
Jul 24, 2014, 4:33:39 AM7/24/14
to tas...@googlegroups.com
I'm confused about this topic.

Is it fixed on the latest tasker version or it still present? Because I'm having the same problem with a webview and an html file.

Kurt Anderson

unread,
Jul 26, 2014, 9:43:54 AM7/26/14
to tas...@googlegroups.com
To get local file access to work...
1. Create a Webview with "File" mode selected, and leave the URI empty.

2. Use "Element Web Control" to load a url of the form "file:///sdcard/....".

Reply all
Reply to author
Forward
0 new messages