Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created April 1, 2016 09:42
Show Gist options
  • Save JavaScript-Packer/7c09491ef30652e5e5f856fb549ed394 to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/7c09491ef30652e5e5f856fb549ed394 to your computer and use it in GitHub Desktop.
Triple clicker JavaScript function, click 3 times fast! Adjust to higher like four or five clicks if you want!
<body>
<h1 onclick="window.scroll(0,7000)"><u style="color:blue">Click HERE to go to bottom!</u></h1>
<script>
window.addEventListener('click', function (x) {
if (x.detail === 3) {
window.scroll(0,0);
}
});
/* MINIFIED
window.addEventListener("click",function(x){if(3===x.detail)window.scroll(0,0)});
*/
</script>
<p><hr size="6666"></p>
<h1>You can TRIPLE CLICK anywhere to get back to the top of the page @ any time!</h1>
<h2>A <a href="http://www.whak.com">WHAK.com</a> JavaScript function gets called!</h2>
</body>
Copy link

ghost commented Jul 14, 2019

That's a very nice and short implementation,
(although it is buggy in Internet-Explorer, it beats counting clicks and using a timer...)

I've personally wasn't even aware of that attribute :]
but Google helped me by directing me here (at first..) and then:
https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event

Since triple-click as some default uses (such as applying selection for an entire block of text or row),
you may add x.preventDefault();1 at first (optional).

Thanks for the example :]

@thepleasehelples
Copy link

where can I make it so it clicks 4 times

@Hqrizon
Copy link

Hqrizon commented Jun 22, 2021

How do I enable it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment