Reputation: 118
I need to check if an window is closed or not. Here is my example,
I have opened a new window by calling this function,
$scope.openwind= function(){
$scope.popupWindow = $window.open("index.html#/channelintegration", "SOme Title", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no');
}
Then I have been checking if the opened window (popupWindow) is closed or not, by calling below function through a button click,
$scope.checkmywindow=function(){
console.log($scope.popupWindow);
console.log($scope.popupWindow.closed);
}
Now, I need to check if the window (popupWindow) is closed or not, without the button trigger.
Pls Help on this.. Thanks..
Upvotes: 0
Views: 1748
Reputation: 118
@Sravan , Thank you for your answer.. It really helped a lot for doing further stuffs.. Now i used below code to check automatically whether the window is closed or not, using $interval service in angular.. This will update a scope variable (windowstatus) every second automatically, with respect to the current status of the window (popupWindow)..
$scope.checkwind = function(){
if (!$scope.popupWindow) {
$scope.windowstatus = "Window hasn't opened yet";
} else {
if ($scope.popupWindow.closed) {
$scope.windowstatus = "Window is Currently Closed"
}
else {
$scope.windowstatus = "Window is Currently Open";
}
}
console.log($scope.windowstatus);
}
$interval( function(){ $scope.checkwind(); }, 100);
Upvotes: 0
Reputation: 18647
You can check if the window is opened or not
, by taking window.open
function in a scope variable and check using the scope.
$scope.openwind= function(){
$scope.popupWindow = $window.open("index.html#/channelintegration", "SOme Title", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no');
}
$scope.closewind= function(){
if ($scope.popupWindow) {
$scope.popupWindow.close();
}
// code for closing goes here
}
$scope.checkmywindow=function(){
if (!$scope.popupWindow) {
document.getElementById("msg").innerHTML = "'$scope.popupWindow' has never been opened!";
} else {
if ($scope.popupWindow.closed) {
document.getElementById("msg").innerHTML = "'$scope.popupWindow' has been closed!";
} else {
document.getElementById("msg").innerHTML = "'$scope.popupWindow' has Opened!";
}
}
}
Upvotes: 1