Prevent iOS Webkit Long Press on Link

16,529

Solution 1

I think you can disable that popup by setting the CSS -webkit-touch-callout property to none on the link. You would do this by editing the HTML or CSS file you're loading, not using Objective-C.

Solution 2

If you want to both disable the popup AND user selection of text on your ENTIRE HTML PAGE, use this on the BODY of your web page or global css.

  body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

Solution 3

What you want to do, as Rob already stated, is to disable the default contextual menu of UIWebView. You can achieve it by adding the following line to webViewDidFinishLoad:

   [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"];
Share:
16,529
Tristan
Author by

Tristan

∆∆∆∆∆∆∆∆

Updated on June 06, 2022

Comments

  • Tristan
    Tristan almost 2 years

    In an iOS app I'm developing, I show an UIWebView to allow the user to upgrade their account. The page contains links to show the user other informations, but you hold your finger on the link, a menu like this will pop up: enter image description here

    As you can see, it reveals the URL of the page and the action that will be performed, which I do not want the user to see, since I don't want them to be able to copy anything as I disabled the "Copy/Cut/Paste" menu already. How would I go about disabling this menu as well?

    Thanks for any pointers.

  • Basil Bourque
    Basil Bourque over 9 years
    This works. But if you are concerned about the user altering your CSS then use the programmatic approach suggested by this other answer. And search for related/duplicate questions and answers.
  • Basil Bourque
    Basil Bourque over 9 years
    You can use * { rather than body { to cover everything.
  • marc_ferna
    marc_ferna over 8 years
    If you want your inputs and textareas to work you need to use *:not(input,textarea) {}