Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibrarySecurity and Blocking

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Double-Tap Catch

Some people tap faster than their browser can respond with. So they tap again. Perhaps several times.

When a link is tapped, the browser needs to fetch the new page before displaying it for the user. Sometimes the browser needs to navigate through redirects before the destination page is found.

Browsers are getting better about offering a blank page immediately after a link is tapped, which removes the link. Yet, even that may be too slow to eliminate an extra tap for particularly active users.

When you record clicks or page loads, those extra taps contaminate your data.

Today's article comes with a JavaScript function that can be used to neutralize the extra taps. You specify which links to enable with the double-tap catch.

The JavaScript takes into consideration that there may, at times, be a legitimate reason to tap a link several times. Currently, it ignores 2 taps (customizable setting) following the first. The next tap is then acted on.

Put the JavaScript on your pages. Give selected links a special onclick attribute. And you're good to go.

Example and JavaScript

The example implementation launches an alert box when the link is tapped. Then, it ignores the next two taps. The tap after that launches the alert box again.

Tap for an alert.

Below is the source code of the JavaScript. It is followed with a customization note and then an example link that uses the JavaScript.

<script type="text/javascript">
// Specify the number of taps to skip after a tap was effective.
var TapCheck_TapsToSkip = 2;
// End of customization.
var TapCheck_TapWasDone = 0;
function TapCheck_CheckFunction()
{
   TapCheck_TapWasDone++;
   if(TapCheck_TapWasDone>(TapCheck_TapsToSkip+1)) { TapCheck_TapWasDone = 1; }
   if(TapCheck_TapWasDone>1) { return false; }
   return true;
}
</script>

Customization note —

The var TapCheck_TapsToSkip = 2; line in the above JavaScript source code specifies the number of taps to ignore after one tap gets through. If you wish to change that, replace 2 with the number you prefer.

Put the JavaScript on your web page wherever JavaScript can run. Near the bottom of the page, immediately above the cancel </body> tag should work. The JavaScript can also be imported instead of the function being coded in the web page.

Enabling the Tap Check Function

To enable the tap check for a link, insert this attribute into the HTML a tag.

onclick="return TapCheck_CheckFunction()"

Here is an example.

<a 
  onclick="return TapCheck_CheckFunction()"
  href="https://www.willmaster.com/blog/javascript/external-javascript.php">
JavaScript can also be imported
</a>

Neutralizing extra taps on links can now be done.

(This article first appeared with an issue of the Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC