Question

I need to run a function when the user clicks on the button on the alert window. Problem I'm having is that using navigator.notification.alert actually runs the call back function as soon as the alert box opens. I also tried.

 navigator.notification.confirm(

but this has the same behavior. The closest I have gotten to running a function just when the user clicks on the button on the pop up window is using notification.prompt.

However this forces an input box on the alert window. Very annoying. So is there any way of doing what I need to do? All I want to do is run a function only after the user has click one of the buttons on the alert box.

There has got to be a work around for this. Can someone give me a tip.

Thanks!

Was it helpful?

Solution

warning and perhaps quite noticeable to other people. in the call back function you cannot pass parameters otherwise you will call the callback function immediately i feel like a big idiot. look below if you do stopfunction(); as supposed to stopfunction you will end up calling the callback function immediately and chase your own tale. Hopefully this helps someone else who might run into this problem. The key hear is that "()"makes an anonymous function in Java script and immediately runs the function.

navigator.notification.confirm(
     'you are aproaching your desired location', // message
      stopFunction,  // callback to invoke with index of button pressed
      'Alarm',      // title
      ['Dismissed']    // buttonLabels
       );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top