简体   繁体   中英

WebView console shows errors on android < 4.0 | (JVectorMap)

I have an issue that's a bit strange... I have a server API where I've installed JVectorMap javascripts to show some stats on maps. it's very simple I just have to set the url to the webview like this:

(WebView Config)

WebView wv = (WebView)lv_header.findViewById(R.id.result_webview);

WebSettings settings = wv.getSettings();
settings.setBuiltInZoomControls(false);
settings.setUseWideViewPort(true);
settings.setJavaScriptEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setDomStorageEnabled(true);
settings.setLoadWithOverviewMode(true); 
wv.setHorizontalScrollBarEnabled(false);

WebView method I call to show map

private void setWebView(String countryCode) {
wv.loadUrl( MyApplication.API_URL_SERVER_PRODUCTION+"/query/"+getIdFromPos(array_id, posInArray)+"/map/"+countryCode);
}

On Android 4.x > will show ok everything is ok but under 4.x I have this log; (And the webView is blank):

E/Web Console(8411): Uncaught TypeError: Object #<an HTMLDocument> has no method: 'createStyleSheet' at http://www.miwebsite.com/static/js/jvectormap/jquery-jvectormap-1.2.2.min.js:7

Method 'createStyleSheet' it's in the "jquery-jvectormap-1.2.2.min.js" file...

Example of a map ==> Click Here

In jVectorMap uncompressed there is a call to document.createStyleSheet() javascript function at line #182:

jvm.VMLElement.initializeVML = function () {
        try {
            document.namespaces.rvml || document.namespaces.add("rvml", "urn:schemas-microsoft-com:vml"), jvm.VMLElement.prototype.createElement = function (e) {
                return document.createElement("<rvml:" + e + ' class="rvml">')
            }
        } catch (e) {
            jvm.VMLElement.prototype.createElement = function (e) {
                return document.createElement("<" + e + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">')
            }
        }
        document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)"), jvm.VMLElement.VMLInitialized = !0
    }

The function is not jVectorMap specific, is specific to the javascript implementation in the IE browser, until IE 11. It's possible you're using a browser that doesn't support this (maybe you're sending the IE user agent string from your Android browser).

Use this uncompressed jVectorMap (copy, paste and save it in a file and use it to replace the minified jVectorMap you currently are using) and see what line is causing the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM