I'm currently creating an image map with webview
. When someone clicks on the hotspots, I'd like to open up another html page named getdir.html
in a popup window of some kind on the same page. I'm guessing I'd need to use JavaScript, but I'm totally new to JavaScript. How can I do this?
This is my code for 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");
this is my image map :
<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>
Edit :
I've tried to open the pop up in JavaScript which is working fine on my computer when I click on the html separately, but not when using webview on device.
What am I doing wrong?
试试这个javascript:
alert("your text here")
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.