问答详情
源自:2-5 JavaScript-打开新窗口(window.open)

拓展一下,打开你想输入的任意网址,仅供参考:

<!DOCTYPE html>

<html>

    <head>

        <title>new document</title>

        <meta charset="UTF-8" />

        <meta http-equiv="Content-Type" content="text/html; charset=gbk" />

    </head>

    <body>

        <input type="button" value="新窗口打开网站" onclick="openWindow()" />

 

        <script type="text/javascript">

            function openWindow() {

                var message = confirm("是否要打开新网站?");

                if (message == true) {

                    var address = prompt("请输入网址");

                    if (address) {

                        window.open("http://"+address, "_blank","width=400,height=500,menubar=no,toolbar=no");

                    }

                } else {

                    alert("已取消");

                }

            }

        </script>

    </body>

</html>


提问者:秋之枫华 2019-11-29 16:12

个回答

  • 秋之枫华
    2019-11-29 16:12:46

    输入网址的时候,不需要输入http协议了