【发布时间】:2012-05-04 12:19:42
【问题描述】:
我目前正在使用webview 创建图像映射。当有人点击热点时,我想在同一页面上的某种弹出窗口中打开另一个名为 getdir.html 的 html 页面。我猜我需要使用 JavaScript,但我对 JavaScript 完全陌生。我该怎么做?
这是我的 webview 代码:
webView = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webView.requestFocusFromTouch();
webView.requestFocus(View.FOCUS_DOWN);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.loadUrl("file:///android_asset/imagemap.html");
这是我的图片地图:
<html>
<body>
<img src="bed_sa.png"
border="0"
usemap ="#imgmap2" />
<script>
function openPopup(url) {
window.open(url, "popup_id", "width=100,height=200");
return false;
}
</script>
<map id="imgmap2" name="imgmap2">
<area shape="rect" alt="first place" title="" coords="139,310,167,342" href="getdir.html" onclick="return openPopup(this.href);" target="" />
<area shape="rect" alt="sec place" title="" coords="142,543,171,571" href="getdir.html" onclick="return openPopup(this.href);" target="_self" />
<area shape="rect" alt="thirrd palce" title="" coords="331,630,358,658" href="getdir.html" onclick="return openPopup(this.href);" target="_self" />
</map>
</body>
</html>
编辑:
我尝试在 JavaScript 中打开弹出窗口,当我单独单击 html 时,它在我的计算机上运行良好,但在设备上使用 webview 时却没有。
我做错了什么?
【问题讨论】:
-
我从来没有尝试过这个,但是你必须为此使用 Javascript,这将打开一个带有你的 getdir.html 文件的新窗口。在地图区域点击调用java脚本函数。还有 mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);用于您的网络视图。
-
实际上,我在几个月前做过类似的事情,但在我的情况下,它是 html5 和 javascript,它在 android 设备中完美运行。我还从网页数据库中获取了坐标。
-
嘿,谢谢你的 rpl 我试过了,但没用 :(
标签: javascript android html webview android-webview