 
		一只特立独行的doge
2016-04-08 09:02
 
  <script type="text/javascript">  
    function openWindow(){
        var message=confirm("are u sure to open a new window?");
        if(message==true){
            var newWebsite=prompt("enter a new website:","http://www.imooc.com/");
            if(newWebsite!=null){
            window.open(newWebsite,'_blank','width=400px,height=500px,toolbar=no,menubar=no');
            }else{document.write("over again!");}
            
        }else{
            document.write("nnothing to do!");
        }
    }
    function closeWindow(){
        var clOpen=confirm("are u sure to close the window?");
        if(clOpen==true){
            newWebsite.close();//请问我该怎样引用到另一个函数里面定义的newWensite呢??
        }else{
            document.write("the window isn't closed!");
            openWindow();
        }
    }
        
    // 新窗口打开时弹出确认框,是否打开
    // 通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/
    //打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
    
    
  </script> 
 </head> 
 <body> 
   <input type="button" value="新窗口打开网站" onclick="openWindow()" />
    <input type="button" value="close the wb" onclick="closeWindow()" /> 
 </body>
</html>我这样定义了两个函数,一个打开一个关闭,可是我关闭的函数里面该怎样引用打开函数里面的值呢,还是需要重新定义?
 
				你中间的close书写有错误,你可以改一下,然后改为window.close{newwebsite};试试,我也是初学,大家互相交流!
 
				http://www.imooc.com/ 网址的 “:”换英文的":"
 
				<script type="text/javascript">
var newWebsite;//此时newWebsite 是全局变量;
function openWindow() {
var message = confirm("are u sure to open a new window?");
if (message == true) {
newWebsite = prompt("enter a new website:", "http://www.imooc.com");
if (newWebsite != null) {
newWebsite = window.open(newWebsite, '_blank', 'width=400px,height=500px,toolbar=no,menubar=no');
} else {
document.write("over again!");
}
} else {
document.write("nnothing to do!");
}
}
function closeWindow() {
var clOpen = confirm("are u sure to close the window?");
if (clOpen == true) {
newWebsite.close();//请问我该怎样引用到另一个函数里面定义的newWensite呢??
} else {
document.write("the window isn't closed!");
//openWindow();
}
}
</script>
//亲测有效,不过不知道这样解释对不对0.0
 
				你用window.open打开,就用window.close关闭就可以了
JavaScript入门篇
741612 学习 · 9869 问题
相似问题