How to use window object closed in JavaScript
In this article, I am going to explain about window object close property.
Closed property in JavaScript window object
In JavaScript window closed property, determine whether a window is closed or not.
Syntax of closed property
Browser support
The closed property is supported in all major browser.
Example of closed property
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var MyWindow;
function openWin() {
MyWindow = window.open("", "", "width=200,height=100");
}
function closeWin() {
if (MyWindow) {
MyWindow.close();
}
}
function checkWin() {
if (!MyWindow) {
document.getElementById("msg").innerHTML = "'MyWindow' has never been opened!";
}
else {
if (MyWindow.closed) {
document.getElementById("msg").innerHTML = "'MyWindow' has been closed!";
}
else {
document.getElementById("msg").innerHTML = "'MyWindow' has not been closed!";
}
}
}
</script>
</head>
<body>
<input type="button" value="Open 'MyWindow'" onclick="openWin()" />
<input type="button" value="Close 'MyWindow'" onclick="closeWin()" />
<br /><br />
<input type="button" value="Has 'MyWindow' been closed?" onclick="checkWin()" />
<br /><br />
<div id="msg"></div>
</body>
</html>
|
Output:
You may also want to read these related articles :here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here