【问题标题】:How to call a function when user click on browser window用户单击浏览器窗口时如何调用函数
【发布时间】:2018-08-16 07:28:17
【问题描述】:

我有一个proceed to payment 按钮,它以target = _blank 重定向到redirectPayment.html 页面并在那里进行支付操作,所以一旦触发支付,我就通过本地存储将标志creditsRefresh 设置为Yes。现在,当支付成功时,它将重定向到成功 jsp 页面。所以用户可以关闭选项卡并返回开始支付的原始选项卡。但我希望在付款后刷新我的金额。因此,如果creditsRefreshyes,我需要在用户单击窗口时调用一个函数。我尝试做onFocusonBlur,它不起作用。

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');
}

付款成功后: $scope.myCredits是支付后刷新金额的功能。

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

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

【问题讨论】:

    标签: javascript angularjs browser


    【解决方案1】:

    我给了 ng-click 并调用了函数。

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

    成功了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      • 1970-01-01
      • 2018-10-26
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多