[英]Get value from DIV element
I want to pass a HTML element value to an Android application. 我想将HTML元素值传递给Android应用程序。 I
一世
I tried retrieving the value using the code below: 我尝试使用以下代码检索值:
document.getElementById(\"summary\").value --> giving null value
document.getElementById(\"summary\").innerHtml --> giving null value
document.getElementById(\"summary\").textContent --> giving null value
I'm trying to implement javascript MutationObserver. 我正在尝试实现javascript MutationObserver。 So whenever there is a change in the content, I can immediately pass the value to the android java code.
所以每当内容发生变化时,我都可以立即将值传递给android java代码。
Can anyone help me? 谁能帮我?
I used the following code: 我使用了以下代码:
myWebView = (WebView)this.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("https://helloworld.com/details");
myWebView.addJavascriptInterface(new JavaScriptInterface(this, myWebView), "MyHandler");
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
myWebView.setWebContentsDebuggingEnabled(true);
}
myWebView.evaluateJavascript("(function(){return document.getElementById(\"summary\").textContent})();",
new ValueCallback<String>() {
@Override
public void onReceiveValue(String html) {
Log.e("HTML Content",html);
}
});
This is my HTML code: 这是我的HTML代码:
<div class="well" id="summary" *ngIf="viewModel != null">
<div class="SuccessSummary">{{viewModel.successSummary}}</div>
</div>
Try this 尝试这个
myWebView.evaluateJavascript("(function(){return
document.getElementById('summary').innerHTML})();",
new ValueCallback<String>() {
@Override
public void onReceiveValue(String html) {
Log.e("HTML Content",html);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.