gpt4 book ai didi

java - 加载本地文件时android webview不执行javascripts

转载 作者:行者123 更新时间:2023-11-30 04:16:40 24 4
gpt4 key购买 nike

我想将本地 jqmobile html 文件加载到 webview 中。我可以使用所有浏览器(包括 Android)打开它,但不能使用 webview。它不会产生任何错误,但是,内容(谷歌地图 v3)不会出现并且不会触发 javascripts!请帮助:(

<uses-library android:name="com.google.android.maps" / > 在我的 list 上以及所有权限。

WebView Activity ,

    browse = (WebView) findViewById(R.id.webview1);
browse.getSettings().setJavaScriptEnabled(true);
browse.getSettings().setUseWideViewPort(true);
browse.getSettings().setLoadWithOverviewMode(true);

browse.setWebChromeClient(new WebChromeClient());

browse.setWebViewClient(new WebViewClient());

browse.loadUrl("file:///data/data/" + PACKAGE_NAME + view1 + ".html");

jqmobile html文件,

<!DOCTYPE wml>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>HTML5 Geolocation</title>

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.js"></script>

<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=true">

<style type="text/css">

html { height: 100%; width:100%;}
body { height: 100%;; margin: 0px; padding: 0px; }
#mapDiv { height: 100%; width:100% }
</style>

</head>
<body >
<div data-role="page" style="height: 100%; width:100%;">
<div data-role="header">
<h1>Localización</h1>
</div>
<div data-role="content" id="mapDiv">
<script language="javascript" type="text/javascript">

var xmlDoc=null;
var xmlHttp=null;
var locations=new Array();
var infowindow = new google.maps.InfoWindow();
var marker, i;
alert("llegint location...");
ConectarLectura();
if (xmlDoc!=null){
var x=xmlDoc.getElementsByTagName("location");
for(i=0;i<x.length;i++){
var punto= new Array();
var item = xmlDoc.getElementsByTagName('location')[i];
var txt = item.getElementsByTagName('nombre')[0];
punto[0]=txt.firstChild.data;
var txt = item.getElementsByTagName('cuerpohtml')[0];
punto[1]=txt.firstChild.data;
var txt = item.getElementsByTagName('latitud')[0];
punto[2]=txt.firstChild.data;
var txt = item.getElementsByTagName('longitud')[0];
punto[3]=txt.firstChild.data;
var txt = item.getElementsByTagName('icono')[0];
punto[4]=txt.firstChild.data;
punto[4]=punto[4].slice(59,punto[4].length);
punto[4]="../../"+punto[4];
locations[i]=punto;
}
}

function ConectarLectura(){

var docdatos=self.location.href.match( /\/([^/]+)$/ )[1];
docdatos=docdatos.substring(0,docdatos.lastIndexOf("."));
docdatos=docdatos+".xml";

alert(docdatos);

xmlDoc=null;
var d= new Date();
var locXML=docdatos+"?"+d.toString();
if (window.ActiveXObject){//Internet Explorer
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET",locXML,false);
xmlHttp.send();
xmlDoc = xmlHttp.responseXML;
}
else if (document.implementation.createDocument){ //Otros navegadores

xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET",locXML,false);
xmlHttp.send(null);
xmlDoc = xmlHttp.responseXML;
}
else{ //Navegadores no compatibles
alert('Browser cannot handle this script');
}
}

if(navigator.geolocation) {

function hasPosition(position) {
var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude),

myOptions = {
zoom: 20,
center: point,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},

mapTypeId: google.maps.MapTypeId.ROADMAP
},

mapDiv = document.getElementById("mapDiv"),
map = new google.maps.Map(mapDiv, myOptions),

marker = new google.maps.Marker({
position: point,
map: map,
title: "Se encuentra aqui",

});
for (i = 0; i < locations.length; i++)
{
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][2], locations[i][3]),
map: map,
icon : locations[i][4]
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][1]);
infowindow.open(map, marker);

}
})(marker, i));

}
//Función para añadir nuevos markers
google.maps.event.addListener(map, 'click', function(event) {

parent.parent.anadePunto(event.latLng);
});

}
navigator.geolocation.getCurrentPosition(hasPosition);
}

</script>


</div>

</div>
</body>
</html>

最佳答案

您使用的是本地存储吗?否则:settings.setDomStorageEnabled(true);

关于java - 加载本地文件时android webview不执行javascripts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9874046/

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