Android - Webview (kitkat and below): Error In Java Script Function 'includes'

依然范特西╮ 提交于 2020-01-17 08:26:40

问题


Trying to Call WebView , While Calling Local Web Page It will Gives Error

Uncaught TypeError: Object ["Some Object"] has no method : 'includes', source: file:///storage/sdcard0/MyDemo/js/fileName.js

It will gives Error To Kitkat and Below. It works Properly above Kitkat.

It was working Fine With gradle Settings below

compileSdkVersion 25
buildToolsVersion "25.0.2"

and Dependancy

compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1

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'

回答1:


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.

You need to make use of indexOf instead 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;


来源:https://stackoverflow.com/questions/47008921/android-webview-kitkat-and-below-error-in-java-script-function-includes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!