Reputation: 749
Based on my previous question ( https://stackoverflow.com/questions/31447508/closing-php-html-window-using-javascript-jquery ), I have figured-out something.
Here below is my code. This code opens my url in a small pop-up. I want to close the opened pop-up window using Javascript.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Auto Play - Video</title>
<script language="javascript" type="text/javascript">
function myPopup() {
window.open( "https://mywebsite/test.php", "myWindow","status = 1, height = 30, width = 30, resizable = 0" )
setTimeout(window.close, 10);
}
</script>
</head>
<body onload="myPopup()">
</body>
</html>
How can I do that? In other words, I need to close the popup window after 10 seconds. Any help will be more helpful.
Upvotes: 0
Views: 4020
Reputation: 2949
As you probably noticed, you are not allowed to pass window.close
directly to setTimeout
.
However, wrapping it in a function works fine:
var customWindow = window.open('http://stackoverflow.com', 'customWindowName', 'status=1');
setTimeout(function() {customWindow.close();}, 10000);
Upvotes: 1
Reputation: 881
Use This Instead
function myPopup() {
var myWindow;
myWindow=window.open( "https://mywebsite/test.php", "myWindow","status = 1, height = 30, width = 30, resizable = 0" );
setTimeout(function () { myWindow.close();}, 10000);
}
Upvotes: 0
Reputation: 1478
To close it automatically after 10 seconds, you need to setTimeout
like this :
function myPopup() {
var win = window.open( "https://mywebsite/test.php", "myWindow","status = 1, height = 30, width = 30, resizable = 0" );
setTimeout( function() {
win.close();
}, 10000);
}
Upvotes: 2
Reputation: 1239
You can try this
<script>
var myWindow;
function myPopup() {
myWindow = window.open("http://www.w3schools.com", "myWindows", "status = 1, height = 90, width = 90, resizable = 0")
setTimeout(wait, 5000);
}
function wait() {
myWindow.close();
}
</script>
Upvotes: 1