Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7002971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:59:58+00:00 2026-05-27T20:59:58+00:00

I am working with JavaScript and jQuery in an UIWevView on iOS. I’v added

  • 0

I am working with JavaScript and jQuery in an UIWevView on iOS.

I’v added some javascript event handler that allow me to capture a touch-and-hold event to show a message when someone taps an img for some time:

$(document).ready(function() {

    var timeoutId = 0;
    var messageAppeared = false;

    $('img').on('touchstart', function(event) {

        event.preventDefault();
        timeoutId = setTimeout(function() {           

            /* Show message ... */
            messageAppeared = true;

        }, 1000);

    }).on('touchend touchcancel', function(event) {                                

        if (messageAppeared) {
            event.preventDefault();
        } else {
            clearTimeout(timeoutId);
        }
        messageAppeared = false;        
    });
});

This works well to show the message. I added the two “event.preventDefault();” lines to stop imgs inside links to trigger the link.

The problem is: This also seems to prevent drag events to scroll the page from happen normally, so that the user wouldn’t be able to scroll when his swipe happens to begin on an img.

How could I disable the default link action without interfering with scrolling?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:59:58+00:00Added an answer on May 27, 2026 at 8:59 pm

    Sometimes you have to ask a question on stack overflow to find the answer yourself. There is indeed a solution to my problem, and it’s as follows:

    $(document).ready(function() {
    
        var timeoutId = 0;
    
        $('img').on('touchstart', function(event) {
    
            var imgElement = this;
    
            timeoutId = setTimeout(function() {           
    
                $(imgElement).one('click', function(event) {
                    event.preventDefault();
                });
    
                /* Show message ... */
    
            }, 1000);
    
        }).on('touchend touchcancel', function(event) {                                
            clearTimeout(timeoutId);
        });
    });
    

    Explanation

    • No preventDefault() in the touch event handlers. This brings back scrolling behavior (of course).
    • Handle a normal click event once if the message appeared, and prevent it’s default action.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on some JavaScript/jQuery code that detected a user agent based against
I have some working JavaScript that I want to convert to pure jQuery. Please
I need help with some Regexp Javascript/JQuery. I got it working, but I think
I'm working on a program that uses HTML/CSS/Javascript/JQuery for its user interface. One of
I'm working on an interactive interface using SVG and JavaScript/jQuery, and I'm trying to
can anybody tell me why is the following code not working? <script type=text/javascript src=../../Scripts/jquery.js></script>
How have you guys handled working with jQuery includes <script type=text/javascript src=jquery.js></script> in Asp.Net
Possible Duplicate: javascript: pause setTimeout(); Im using jQuery and working on a notification system
I need JavaScript working almost perfectly in my application that should be able to
I am working on a javascript app that users load via a configurable script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.