[英]WebView console shows errors on android < 4.0 | (JVectorMap)
我有一個奇怪的問題...我有一個服務器API,在其中安裝了JVectorMap javascript,以在地圖上顯示一些統計信息。 這非常簡單,我只需要將網址設置為如下所示的webview:
(WebView配置)
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方法
private void setWebView(String countryCode) {
wv.loadUrl( MyApplication.API_URL_SERVER_PRODUCTION+"/query/"+getIdFromPos(array_id, posInArray)+"/map/"+countryCode);
}
在Android 4.x上>將顯示ok,但一切正常,但是在4.x下,我有此日志; (並且webView為空白):
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
方法“ createStyleSheet”位於“ jquery-jvectormap-1.2.2.min.js”文件中...
地圖示例==> 單擊此處
在未壓縮的jVectorMap中,在第#182行有一個對document.createStyleSheet()
javascript函數的調用:
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
}
該函數不是特定於jVectorMap的,而是特定於IE瀏覽器中的javascript實現的,直到IE 11為止。可能您使用的瀏覽器不支持此功能(也許是從Android發送IE用戶代理字符串)瀏覽器)。
使用此未壓縮的jVectorMap (將其復制,粘貼並保存到文件中,並用其替換您當前使用的縮小的jVectorMap),然后查看引起此問題的行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.