I have the following code:
var exitHandler=function(){
return "Are you sure you want to move from this page.";
}
angular.element($window).bind("beforeunload", exitHandler);
When I close the browser tab it opens a popup confirmation:
"Are you sure you want to unload this page ?"
Up till here it is ok, but I want to perform some API call, when the user clicks on the OK button, but not on the CANCEL button. Is there any way to do this? I have to perform this operation just after clicking on the OK button:
Participant.setDorateStatus({id:localData.userId},{dorate2status:true})
.$promise.then(function(data) {
console.log(data)
endExperiment=data;
})
.catch(function(err) {
if (err.status != 401)
$scope.addNotification("something went wrong.", "danger", 5000);
})
and I want when the API call returns success then the tab will close, if it will return error the tab will remain unclosed.