How to call a function when user click on browser window

I have a proceed to payment button and it redirect to redirectPayment.html page as target = _blank and do payment operations there, so I had set a flag creditsRefresh as Yes by local storage once payment is triggered. Now when payment is successfull , it will redirect to success jsp user can close the tab and come back to original tab where payment initiated.But I want my amount to be refreshed after payment. So I need to call a function when user click on window if creditsRefresh is yes .I tried doing onFocus or onBlur , it doesnt worked.


<button class="btn btn-primary" ng-click="initiatePayment(CreditDetails);">Proceed to pay</button>


$scope.initiatePayment = function(){

After success payment:
$scope.myCredits is the function which will refresh my amount after payment.

 $scope.focusOnPageCall = function(){    
            if ($window.localStorage.getItem('creditsRefresh') == 'yes'){
              $window.localStorage.setItem('creditsRefresh' ,'no');

    $window.onfocus = $scope.focusOnPageCall();   

Source: AngularJS