# 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 page.so 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.

payment.html

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


Paymentcontroller.js

$scope.initiatePayment = function(){$window.localStorage.setItem('creditsRefresh','yes');
$window.open('/redirectPayment','_blank'); }  After success payment: $scope.myCredits is the function which will refresh my amount after payment.

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

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


Source: AngularJS

This site uses Akismet to reduce spam. Learn how your comment data is processed.