-2

i don't want to use the double click function , instead i just want to run the below buttonOnClick() when a user click two times not single time , Help me iam new to coding

                <button onclick="buttonOnClick();" onmouseover="mouseOver();" onmouseout="mouseOut();">Subscribe <i id="ytb" class="fa fa-youtube-square ytb"></i></button>
                <br>


             </div>

function buttonOnClick()

{


  window.open('https://www.youtube.com/channel/UCXE6pw29K2lHS_2fB8LeU1Q?sub_confirmation=1','_blank');



  setTimeout(aTagChange, 12000);

}
  • 1
    Possible duplicate of [how to differentiate single click event and double click event?](https://stackoverflow.com/questions/5497073/how-to-differentiate-single-click-event-and-double-click-event) – pr1nc3 Mar 04 '19 at 08:04
  • Why don't you want `dblclick` when you want to ignore single clicks at all? – Pinke Helga Mar 04 '19 at 08:11
  • hi cause by properller ads , it load the onpage script , which covers the whole page , so when a user click on button , without going to the target url it takes it as a Click and runs the function , – mrniamster Mar 04 '19 at 08:16
  • Are you writing a GreaseMonkey/TamperMonkey userscript? – Pinke Helga Mar 04 '19 at 08:19
  • no , bro nothing like that – mrniamster Mar 04 '19 at 08:20
  • Why can't you overwrite the `onclick` event to do nothing and additionally add the `dblclick` listener? – Pinke Helga Mar 04 '19 at 08:25
  • quasim, the prevClick method by jack worked, but its not working from my mobile , from pc its working – mrniamster Mar 04 '19 at 08:37

2 Answers2

3

Set a variable prevClick then update and check it:

var prevClick = false;
function buttonOnClick() {
    if (prevClick) {
        window.open('https://www.youtube.com/channel/UCXE6pw29K2lHS_2fB8LeU1Q?sub_confirmation=1','_blank');
        setTimeout(aTagChange, 12000);
    } else {
        prevClick = true;
    }
}
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
2

You can use ondblclick

function func(){
  console.log("double clicked");
}
<button ondblclick="func()">Subscribe <i id="ytb" class="fa fa-youtube-square ytb"></i></button>
You can have a Boolean to check if the its clicked once or not

let clicked = false;
function func(){
  if(clicked === false){
    clicked = true;
    return false;
  }
  else clicked = false;
  console.log("clicked second time");
  
}
<button onclick="func()">Subscribe <i id="ytb" class="fa fa-youtube-square ytb"></i></button>
Maheer Ali
  • 35,834
  • 5
  • 42
  • 73