ev66
09-25-2006, 02:21 PM
why is it that when the newwin variable is declared outside the myfunc() function, the closewin() function works and closes the window,
but when newwin is declared inside the myfunc(), the closewin() function does not work ?
THIS WORKS
<head><script type="text/javascript">
var newwin;
function myfunc() {
newwin=window.open("","","width=300,height=300")
}
function closewin(){
if(newwin){ newwin.close();}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<input type="button" value="click me" onclick="myfunc()" />
<input type="button" value="close" onclick="closewin()" />
</body>
THIS DOES NOT WORK
<head><script type="text/javascript">
function myfunc() {
var newwin=window.open("","","width=300,height=300")
}
function closewin(){
if(newwin){ newwin.close();}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<input type="button" value="click me" onclick="myfunc()" />
<input type="button" value="close" onclick="closewin()" />
</body>
thank you
but when newwin is declared inside the myfunc(), the closewin() function does not work ?
THIS WORKS
<head><script type="text/javascript">
var newwin;
function myfunc() {
newwin=window.open("","","width=300,height=300")
}
function closewin(){
if(newwin){ newwin.close();}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<input type="button" value="click me" onclick="myfunc()" />
<input type="button" value="close" onclick="closewin()" />
</body>
THIS DOES NOT WORK
<head><script type="text/javascript">
function myfunc() {
var newwin=window.open("","","width=300,height=300")
}
function closewin(){
if(newwin){ newwin.close();}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<input type="button" value="click me" onclick="myfunc()" />
<input type="button" value="close" onclick="closewin()" />
</body>
thank you