Forum Moderators: open
<div id="winobject">
<input type="button" value="Open" />
<input type="button" value="Close" />
<input type="button" value="Confirm" />
</div>
<div id="msg"></div
function prepInputElements(){
var myWindow;
if(!document.getElementsByTagName) return false;
if(!document.getElementById) return false;
if(!document.getElementById("winobject")) return false;
var mydiv = document.getElementById("winobject");
var myinputs = mydiv.getElementsByTagName("input");
var myid = document.getElementById('msg');
mytextnode = document.createTextNode("Window status.");
myid.appendChild(mytextnode);
for(var i=0; i < myinputs.length ; i++){
if(myinputs[i].getAttribute("value") == "Open"){
myinputs[i].onclick = function() {
myWindow = window.open('','','width=400,height=200');
myid.firstChild.nodeValue = "Window is open.";
}
}
if(myinputs[i].getAttribute("value") == "Close") {
myinputs[i].onclick = function() {
if (myWindow){
myWindow.close(); //<<<<<<<NOT CLOSING THE WINDOW
myid.firstChild.nodeValue = "Window is closed.";//<<BUT, THIS WORKS!
}
}
}
if(myinputs[i].getAttribute("value") == "Confirm") {
myinputs[i].onclick = function() {
if (!myWindow){
myid.firstChild.nodeValue = "Window has not been opened.";
} else {
if (myWindow.closed) {
myid.firstChild.nodeValue = "Window has been closed.";
} else {
myid.firstChild.nodeValue = "Window has not been closed.";
}
}
}
}
}
}
addLoadEvent(prepInputElements);