Ways to execute a function upon clicking the browser window

When a user clicks on the proceed to payment button, it redirects to the redirectPayment.html page with target=_blank for payment operations. After triggering the payment, a flag called creditsRefresh is set to Yes using local storage. Upon successful payment, the user is redirected to a success JSP page. However, I want to refresh the amount after payment and bring the user back to the original tab where the payment was initiated. To achieve this, I need to call a function when the user clicks on the window if creditsRefresh is set to yes. My attempts with using onFocus or onBlur have been unsuccessful.

Code snippet from payment.html:

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

Snippet from Paymentcontroller.js:

$scope.initiatePayment = function(){
 $window.localStorage.setItem('creditsRefresh','yes');
 $window.open('/redirectPayment','_blank');
}

After a successful payment, the $scope.myCredits function will be used to refresh the amount.

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

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

Answer №1

I included ng-click and triggered the function.

<div class = "container" ng-click = "executePageFunction()">
<div>
<button class="btn btn-primary" ng-click="startPaymentProcess(CreditDetails);">Continue to checkout</button>

</div>
</div>

Success!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing clickable table rows in React Router Link for seamless navigation

I'm relatively new to working with React. In my project, there is a Component called Content, which acts as a container for two other components - List and Profile. class Content extends Component{ <HashRouter> <Route exact path="/ ...

Encountering Axios CanceledError while attempting to forward a POST request using Axios

While attempting to relay a POST request from an express backend to another backend using axios, I encountered an axios error stating "CanceledError: Request stream has been aborted". Interestingly, this issue does not arise when dealing with GET requests. ...

Verify the ability to view a webpage

I am currently working on creating a method to check if data access is equal to next.data.access. Since it's an array, I cannot use the includes method. It would be enough for just one of the data access values in the array to return true. auth.guard ...

D3 group of legendary elements

Is there a way to group both the circle and text elements for each legend item together? I'm currently facing a challenge with the enter/exit methods. While I can create the groups (g), I'm unable to append the text and circle elements. li.sel ...

Instructions for rotating a Vector3 in Three.js along an axis

Is there a way to rotate a Vector3 from Three.js around an axis by a specific angle? I need help with this process. ...

Creating a TextGeometry in THREE JS that Reacts to Mouse Movements

I have created a unique source code where the text rotates based on mouse position. // Setting up the scene const scene = new THREE.Scene(); let camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ) ...

Ajax Syntax Error: Unexpected Token U

I have been struggling all day with an issue while trying to send json data via ajax to Express. Here is how my ajax code looks like: $('#saveClause').click(function () { var username = document.getElementById('postUserName').inne ...

Guide on transferring a JSON string from a JSP page to a Spring MVC controller

I am facing an issue while trying to pass a simple json string to my controller. The json string is not being received at the controller end. I have other functionalities like inserting, deleting, etc., inside my controller code which work perfectly fine, ...

Tips for configuring CakePHP to trigger the second submit button when the enter key is pressed

My form includes two submit buttons: "cancel" and "find." While both buttons work correctly when clicked, pressing the enter key always triggers the submission of "cancel." I don't want to change the button order in the form. To address this issue, I ...

The $scope variable is not retaining the value for the ng-repeat directive

I'm struggling to implement an ng-repeat on data fetched from an API in JSON format. The issue I'm facing is that even though I can see the data in $scope.wines when I console.log() before the function ends, the data seems to disappear by the end ...

Error: The 'browser' field in the NPM configuration is missing a valid alias setting

When running the following command: node .\node_modules\webpack\bin\webpack.js --config scripts/webpack.config.js --display-error-details An error is generated with the following details. Currently, I am testing the script and my ...

Mastering the ng-model Directive and Harnessing its Controller in Custom Directives

Recently, I crafted a custom directive that envelops the jstree functionality and incorporated ng-model within the tag of my directive to transmit certain JSON data. I am pondering: Is it necessary for me to utilize ng-model in this particular scenario? ...

Instructions for selecting the initial year in the date of birth dropdown menu

I am working on code that displays date of birth values and I want to enhance it by adding another function in the JavaScript. However, I am unsure about the best approach to do so. The default age is set at 2000 and users cannot go any lower as the minim ...

Guide on developing a Vue modal for transferring user input to a separate component

I have been working on creating a modal component that allows users to input data and then displays it in another component. For example, the user is prompted to enter their first and last name in a modal component (Modal.vue). Once the user saves this inf ...

What is the best way to ensure that my multiple choice code in CSS & JS only allows for the selection of one option at a time? Currently, I am able

I'm currently facing a small issue that I believe has a simple solution. My knowledge of Javascript is limited, but I am eager to improve my skills in coding for more visually appealing websites. My problem lies in the code snippet below, where I am ...

Drop-down menu with caret using HTML and CSS

Is there a way to include a dropdown caret for the account link in the html code provided below? . . . <nav> <ul id="menu"> <li class="home"><a href= "home.html" class="menu" >&l ...

Can props.children be given a ref without any existing ref?

Consider this scenario... MainComponent.js <Wrapper> <p ref={React.createRef()}>{state.item1}</p> <p>{state.item2}</p> <p>{state.item3}</p> <p>{state.item4}</p> </Wr ...

Guide on utilizing the History API or history.js to dynamically update the "active" link based on page refreshes and back button presses

Highlighted active links using JS on my website. <script type="text/javascript> $(document).ready(function(){ $("a.nav1").click(function() { $(".active").removeClass("active"); $(this).addClass("active"); ...

Retrieve the values of all child attributes in the XML file

This is a sample XML structure: <child_2 entity_id="2" value="Root" parent_id="1"> <child_4 entity_id="4" value="Activities" parent_id="2"> <child_10066 entity_id="10066" value="Physical1" parent_id="4"> <child ...

What is the process for managing items in an array within a separate file?

I am facing an issue where I need to display the 'title' object from an array in the document App.js. Everything works fine when I use an array without any objects: (before) App.js: import React from 'react' import TodoList from ' ...