在 Web 视图中打开弹出窗口

open a pop up a window in a webview

本文关键字:窗口 Web 视图      更新时间:2023-09-26

我目前正在创建一个带有webview的图像映射。当有人点击热点时,我想在同一页面上的某种弹出窗口中打开另一个名为 getdir.html 的 html 页面。我猜我需要使用 JavaScript,但我对 JavaScript 完全陌生。我该怎么做?

这是我的网页视图代码:

    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:

alert("your text here")
相关文章: