Answer the question
In order to leave comments, you need to log in
How to make http request in JS in Android WebView?
In WebView, I load a local page from assets containing the following script.
var request = new XMLHttpRequest();
//request.open("GET", "file:///data/data/package/files/TEMP", true);
request.open("GET", "https://epub-samples.googlecode.com/files/moby-dick-20120118.epub", true);
request.responseType = 'blob';
request.onload = function () {
console.log("Q!" + request.status);
var resp = request.response;
console.log(resp.size);
};
request.send();
console.log(resp.size);
super.getSettings().setJavaScriptEnabled(true);
super.getSettings().setAllowContentAccess(true);
super.getSettings().setAllowFileAccess(true);
super.getSettings().setAllowFileAccessFromFileURLs(true);
super.getSettings().setAllowContentAccess(true);
super.getSettings().setAllowUniversalAccessFromFileURLs(true);
super.setWebChromeClient(new WebChromeClient());
super.loadUrl("file:///android_asset/html/mono.html");
Answer the question
In order to leave comments, you need to log in
Wrap your JS code in a function. Download it as before. And then the function can be called like this:super.loadUrl("javascript:foo(var1, var2.....");
As Google has shown, starting with Android 4.4 WebView uses updated and uses Chromium code and has a new JS engine. https://developer.chrome.com/multidevice/webview/o... The
old WebView doesn't seem to know XMLHttpRequest.
Use 'W' instead of 'z'
W Week number of the year according to ISO-8601; weeks start on Monday For example: 42 (the 42nd week of the year)
$msg = date('W') % 2 ? 'Нечетная неделя' : 'Четная неделя';
$siteglobal['insert']['week'] = date("j.m.Y") . "<br />" . $msg;
echo $siteglobal['insert']['week'];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question