Android-Webview(kitkat及更低版本):Java脚本函数“ includes”中的错误 [英] Android - Webview (kitkat and below): Error In Java Script Function 'includes'
问题描述
尝试调用WebView时,将在调用本地网页时出现错误
Trying to Call WebView , While Calling Local Web Page It will Gives Error
未捕获的TypeError:对象[ Some Object]有没有方法:'includes',
来源:file:///storage/sdcard0/MyDemo/js/fileName.js
Uncaught TypeError: Object ["Some Object"] has no method : 'includes', source: file:///storage/sdcard0/MyDemo/js/fileName.js
它将为Kitkat及以下提供错误。
可以在Kitkat上面正常工作。
It will gives Error To Kitkat and Below. It works Properly above Kitkat.
在下面的gradle设置下可以正常工作
It was working Fine With gradle Settings below
compileSdkVersion 25
buildToolsVersion "25.0.2"
和依赖项
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1
当前正在使用Gradle设置。
Currently Using Gradle settings.
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId ""
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
}
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:support-v13:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
推荐答案
发生这种情况是因为您使用的是 includes
方法在字符串我n您的js文件受最新JavaScript版本 ECMAScript 6 支持,而android kitkat webview不支持此版本。
This is happening because you are using includes
method on string in your js file, which is supported in latest JavaScript Version ECMAScript 6 and android kitkat webview doesn't support this version.
使用 indexOf
代替 includes
var str = "Hello world, welcome to the universe.";
var n = str.includes("world");
# Replace above line of code and use indexOf.
var n = str.indexOf("world") > -1;
这篇关于Android-Webview(kitkat及更低版本):Java脚本函数“ includes”中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!