[英]how to access local data from external webpage?
I'm trying to access the data inside the assets/css from an external HTML file. 我正在尝试从外部HTML文件访问assets / css中的数据。
The process goes like this: 过程如下:
<html>
<head>
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, height=device-height, user-scalable=yes" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ola</title>
<link rel="stylesheet" type="text/css" href="file:///android_asset/css/main.css" />
<link rel="stylesheet" type="text/css" href="file:///android_asset/css/sch.css" />
<script type="text/javascript" src="file:///android_asset/css/ethan.js" />
<script type="text/javascript" src="scripts/allinone.js" />
</head>
<body>
<input id="btnTest1" name="button" type="button" style="height:0px;width:0px;" />
</body>
</html>
So here the thing is that, I'm actually calling the HTML file using a link (since the HTML file is not locally present). 所以事情是,我实际上是使用链接调用HTML文件(因为HTML文件不是本地存在的)。 But
main.css
, sch.css
and ethan.js
are locally present in the assets/css folder. 但是
main.css
, sch.css
和ethan.js
本地存在于assets / css文件夹中。
What I'm trying to do is to load the allinone.js
which is obviously external and the other three files into the which are internal and run the script. 我正在尝试做的是加载
allinone.js
,这显然是外部的,其他三个文件加载到内部并运行脚本。
I found " file:///android_asset/css/main.css
" but it looks like it doesn't work. 我找到了“
file:///android_asset/css/main.css
”,但看起来它不起作用。
Please help.... 请帮忙....
I would be curious to know more about the use case here. 我很想知道这里的用例。 My understanding is this:
我的理解是这样的:
If that's so -- and given that the logical approach you conceived of using the file:// URI does not work -- there would seem to be two options, each making use of the webView API: 如果是这样 - 并且考虑到您构想使用file:// URI的逻辑方法不起作用 - 似乎有两个选项,每个选项都使用webView API:
mWebView.loadUrl("javascript:injectJavascript(js)");
where the parameter 'js' is some inline Javascript that you load within your Android code, and injectJavascript
is a method in the remote HTML file that actually inserts it into your DOM. 其中参数'js'是您在Android代码中加载的内联Javascript,而
injectJavascript
是远程HTML文件中实际将其插入DOM的方法。 Take an analogous approach to insert your CSS ... 采用类似的方法插入CSS ...
Admittedly these approaches are a bit hackish. 不可否认,这些方法有些过时。 Ideally you would use a custom method of the WebView class like 'addCssToDom' or something, but as far as I can see, no such methods are available.
理想情况下,您将使用WebView类的自定义方法,如“addCssToDom”或其他东西,但据我所知,没有这样的方法可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.