gpt4 book ai didi

javascript - Android Webview 错误 IN/chromium : [INFO:CONSOLE(1)] "Uncaught ReferenceError:

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:01 30 4
gpt4 key购买 nike

我有一个 web 服务,因为我已经为 android 添加了条形码阅读器

所以在 JavaScript 的帮助下,我从 WebView 调用我的条形码阅读器

因此 I followed this

在服务器端设计...我给了这个

在 JavaScript 上

    function mybarcd() {
MyApp.mybarcdt();
}

function actfromAnd(msg){
document.getElementById("brcd").value = msg;
}


at HTML/PHP

<div class="data">
<input id="brcd" type="text" value=""/>
<button type="button" onClick="mybarcd()">SCAN</button>
</div>

在 Android 端在 WebView 中

    webView.addJavascriptInterface(new WebAppInterface(this), "MyApp");

和新的js接口(interface)

    @JavascriptInterface
public void mybarcdt() {

IntentIntegrator intentIntegrator = new IntentIntegrator(Main_A.this);
intentIntegrator.setBeepEnabled(true);
intentIntegrator.setOrientationLocked(true);
intentIntegrator.setPrompt("Scan Barcode");
intentIntegrator.initiateScan();
}



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
if (result.getContents() == null) {
Log.d("ScanActivity", "Cancelled scan");
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();

} else {

Log.d("ScanActivity", "Scanned");

String bcval = result.getContents();
if (android.os.Build.VERSION.SDK_INT < 19) {
webView.loadUrl("javascript:actfromAnd(\""+bcval+"\")");
}else{
webView.evaluateJavascript("javascript:actfromAnd(\""+bcval+"\")", null);
}
System.out.println("javascript:actfromAnd(\""+bcval+"\")");

}
} else
super.onActivityResult(requestCode, resultCode, data);
}

我的问题是它在同一页面或单独页面上带有 Js 的单个 Html/PHP 文件中工作正常我已经测试了它的扫描和更新输入框中的值...

但它不起作用,因为我在一个 webview 中使用了多个页面或框架......它缺少 JS 值...如何在单击时形成服务器其打开扫描仪...但是在扫描值后未使用 JS 传递到输入框我收到此错误......

I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: actfromAnd is not defined", source:  (1)

更新

1)我已经在静态页面中尝试过这个,在 PHP/HTML 页面中使用 JS
2)我也尝试在带有 JS 单独页面的静态页面中使用相同的
在以上两个条件下它工作正常

但是在我的网络服务中,我给定了相同的 JS 文件,它在静态页面中成功运行,我有一个 JS 文件用于我的 Web 服务和静态页面,它在静态中工作正常,但在我的网络服务中不能实时工作。如何JS 正在加载因为点击它从那个 JS 和它的开放相机中工作但是扫描后的响应不是网页输入

我知道我收到错误是因为...

In my Live Page I have a MainMenu Inside that menu when I select a application its loading in iframe So my Android Activity responce after scanning Is pinging to that Mainmenu page But for menu there is no Js function named actfromAnd So I am getting Error...

这里我不能给出那个特定页面的 URL(iframe) 因为取决于菜单,它会改变我可以直接给出 Only Login 或 MainMenu 链接。但不能为里面的特定页面菜单

任何人都可以建议我这种...

最佳答案

在您的父菜单的网络服务中添加此脚本,其中包含您的 iframeiframe

<script>
function actfromAnd(msg){
window.frames['yourExactframe'].document.getElementById("brcd").value = msg;
}
</script>

如果您在多个框架中使用相同的框架,则全局声明您的框架名称

我试过你的代码工作正常......在我的例子框架希望它适合你

好问题....

关于javascript - Android Webview 错误 IN/chromium : [INFO:CONSOLE(1)] "Uncaught ReferenceError:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43153916/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com