tags:

views:

46

answers:

4

Lets say we have a js function which shows a pop up on a button click. But if the button is clicked twice in a hurry it show two popups. Is there any way to prevent alert to show two pop ups when the button is clicked twice in a hurry?

A: 

you could set a variable to store a flag to say the alert is already been shown?

//outside the event
var flagShown = false;

// in the event
if(!flagShown){
alert();
flagShow = true;
}

I havent tested this code...

HTH

Edit: this will make it show only once. You would have to reset the flag based on a timer or on some other event.

DannyLane
You mean to say the flag must change its values after a perticular interval of time otherwise the alert mgs will appear only once.
Nadeem
One way to do it would be time based, set a timer for a couple of seconds and then reset the flag afterwards. another way would be to reset the flag in a different event i.e. when the user does something else.
DannyLane
Yeah I got the idea. See my answer. I tried to implement the same and this seems to be working for me. Anyways thanks dude!!!!
Nadeem
A: 

using a var that store the fact that a display is under way ?

Could not check as I'm not able to clic fast enough for 2 clics to be triggered...

var alert_under_way=0;

function doIt()
{
if (! alert_under_way)
  {
  alert_under_way =1;
  alert("toto");
  alert_under_way =0;
  }
}
dodecaplex
A: 

You could also disable the button once its been clicked and enable it again if you need to. Up your accept rate and Ill post some code.

James Westgate
A: 

I have used the following code to prevent the display of two popups:

var prevent_popup=false;

        function show_popup()
        {
            .....
            .....
            if(!prevent_popup)
            alert("some text");
            prevent_popup=true;
            setTimeout('prevent_popup=false;',1000);
            .....
            .....
        }
Nadeem