Answer the question
In order to leave comments, you need to log in
How to avoid double click?
Good day!
Tell me, plz, in such a situation?
I have a button on the page with a link, like "Next". And there is also a code, thanks to which, the transition is carried out when you click on any point on the page. This is done so that if users miss the button, the transition will still occur (users usually come from mobile devices).
The code for this is:
<style>
BODY.enterPage{
cursor:hand;
}
</style>
<script>
function goto(){
location.href = "domain.com/next"
}
</script>
<body class="enterPage" onclick="goto();">
Answer the question
In order to leave comments, you need to log in
You can check event.target in the body click event handler and make the transition only if it is a click not on a link.
You can hang a click event handler on the link and prevent the event from popping up
https://learn.javascript.ru/event-bubbling
A double click can usually occur for the following reasons:
1) A handler for the same event is set for the element itself and for the container element in which it is located. In this case, the event.stopPropagation() method will help, which prevents the event from bubbling.
2) Additionally, the browser's built-in handler is triggered (in particular, when you click on a link, the browser will try to follow it). To prevent the browser from doing something by default, use the event.preventDefault() method. This method is often used in conjunction with the previous one.
3) The user makes 2 clicks in a row too quickly. In this case, you need to call the handler no earlier than a certain time after the last operation ( debounce )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question