I am developing a javascript class (with jQuery) to create a custom popup, but I can’t figure out how to “pause” the script to wait for the user to respond (click OK or cancel)
the class is as follows:
function Popup()
{
}
Popup.Show = function(text)
{
var _response;
$("#button-ok").on("click",function()
{
_response = "ok!"
}
return _response
}
if, for example, you use it in a warning, the method always returns "undefined" because it does not wait for a button to be pressed
alert(Popup.Show("hello"))
//return undefined before the popup appears
I tried using the while loop as follows:
Popup.Show = function(text)
{
var _response;
var _wait = true;
$("#button-ok").on("click",function()
{
_wait = false;
_response = "ok!"
}
while(_wait){};
return _response
}
but does not work (as I expected)
Then, how to wait for the user to click?
Thank you all
source
share