问答详情
源自:2-7 编程练习

如何实现新窗口中弹出网页内容是在prompt里面输入的网址? 不能直接用message放在windows.open里面?

<!DOCTYPE html>

<html>

 <head>

  <title> new document </title>  

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

  <script type="text/javascript">  

 function openWindow()

  {

  var message=prompt("请输入对应网址", "");

  if (message==false)

  { alert("wrong address");

  }

  else

      { rec(); }

  }

  function rec()

  {

  var a=confirm("是否打开网页?");

   if (a==true)

   { window.open('message','_blank','width=600,height=400,menubar=no,toolbar=no, status=no,scrollbars=yes'); }

   else { alert("您已取消进入")}

  }

  </script> 

 </head> 

 <body> 

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

 </body>

</html>


提问者:rainy_li3676598 2016-09-21 11:02

个回答

  • 只能改了
    2016-09-21 11:30:54
    已采纳

    <!DOCTYPE html>

    <html>

     <head>

      <title> new document </title>  

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

      <script type="text/javascript">  

     function openWindow()

      {

      var message=prompt("请输入对应网址", "");

      if (message==false)

      { alert("wrong address");

      }

      else

          { rec(message); }

      }

      function rec(net)

      {

      var a=confirm("是否打开网页?");

       if (a==true)

       { window.open(net,'_blank','width=600,height=400,menubar=no,toolbar=no, status=no,scrollbars=yes'); }

       else { alert("您已取消进入")}

      }

      </script> 

     </head> 

     <body> 

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

     </body>

    </html>


  • 慕沐3390597
    2016-09-21 11:31:02

    message没有传过去。window.open 这里的message,你使用了单引号,代表的是一个字符串了。要用变量,就要去掉引号。可以改成

    else{ 

    rec(message);

    }

     window.open(message,'_blank','width=600,height=400,menubar=no,toolbar=no, status=no,scrollbars=yes'); 

  • weibo_一半冰山i_0
    2016-09-21 11:25:13

    var message=prompt("请输入对应网址", "");

    message会被赋值为输入的网址,例如你输入的是“http://www.imooc.com/”;

    message放在window.open里如下所示:

    window.open(message,"_blank","width=600,height=400,menubar=no,toolbar=no, status=no,scrollbars=yes");