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 8755545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:52:42+00:00 2026-06-13T13:52:42+00:00

The deafult pop up is get opened when I long press the music play

  • 0

The deafult pop up is get opened when I long press the music play option in any url from UIWebView.
I Want to add one more button in the pop up..Is it possible to do it..

Like I want to add FETCH button.

And Can I make changes in the default pop up functioning which is OPEN and COPY. shown below

enter image description here

I come to know that by google –

First of all, you really can’t add additional menu items to the default ones of the standard contextual menu. But you can switch off the contextual menu using a certain CSS property. So the solution would be to switch off the default menu and implement your own from scratch. And to implement your own contextual menu, you have to first catch the tab-and-hold gesture, get the coordinates of the finger on the screen, translate these coordinates into the coordinate system of the web page and finally look for the HTML elements at this location.

  • 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-06-13T13:52:43+00:00Added an answer on June 13, 2026 at 1:52 pm

    NEW ANSWER:

    Looks like this is what we want, here:

    https://stackoverflow.com/a/3198220/700471

    OLD ANSWER:

    Okay, after some research, here’s the deal:

    What you describe in your question seems accurate:

    First of all, you really can’t add additional menu items to the
    default ones of the standard contextual menu. But you can switch off
    the contextual menu using a certain CSS property. So the solution
    would be to switch off the default menu and implement your own from
    scratch. And to implement your own contextual menu, you have to first
    catch the tab-and-hold gesture, get the coordinates of the finger on
    the screen, translate these coordinates into the coordinate system of
    the web page and finally look for the HTML elements at this location.

    So you are planning on implementing your own popover controller with contextual menu–fine, I won’t get into that at all, I will assume you know how to do that.

    What your question seems to be is, how do you take a long-tap gesture in the UIWebView and transform it into the coordinates of the webpage to find the DOM element that was selected, and use that as a context from which to generate your popover menu.

    What I found was this, specifically this with this line of code:

    NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).innerHTML", touchPoint.x, touchPoint.y];
    

    That looks like the JS you would need to figure out what element had just been long-pressed, and of course you would need to do some figure-figure to see if it was a link and execute your context menu from there, but that’s not something I’ve looked into.

    Some further thoughts:

    Probably the easiest course would be to attach a UILongPressGestureRecognizer to your UIWebView (this can be done easily in a nib) and make sure that the “Sent Action” points to an appropriate IBAction on your ViewController. (I suppose you could use the delegate outlet as well, but I have never needed to do that.)

    In any case, you can use the locationOfTouch:inView: method of your gesture recognizer, and the view you will probably want to use will be the UIWebView’s content view, which I believe you can get with something like myWebView.scrollView.subviews[0] (or the objectAtIndex: variation if you are not using the new array index subscripts).

    Anyway, I think I have provided enough to answer your question.


    EDIT:

    Okay, so you are still having trouble with this, so I went and made a test project and got it to work. One thing that is slightly annoying about this is that WebKit somehow adds a “buffer” area around objects in the DOM, meaning that if you touch slightly next to a link it will still highlight, but when you use the JS command elementFromPoint it doesn’t do that, so you kinda have to touch more carefully to trigger the popup using this method. But, it works.

    I made a blank project with the “single view” template, and threw a UIWebView into the xib, pointed its delegate outlet to File’s Owner. Then I put a UILongPressGestureRecognizer into the xib, attached to the UIWebView. I set its delegate as File’s Owner, and set its selector outlet to the longPressDetected IBAction in File’s Owner. I also unchecked “Canceled in View” in the recognizer’s properties in Interface Builder.

    Here is the code for the view controller.

    Interface:

    //
    //  WVTViewController.h
    //  WebViewTest
    //
    
    #import <UIKit/UIKit.h>
    
    @interface WVTViewController : UIViewController <UIWebViewDelegate, UIGestureRecognizerDelegate>
    
    @property (nonatomic, weak) IBOutlet    UIWebView   *myWebView;
    @property (nonatomic)                   BOOL        didFirstLoad;
    
    - (IBAction)longPressDetected:(id)sender;
    
    @end
    

    Implementation:

    //
    //  WVTViewController.m
    //  WebViewTest
    //
    
    #import "WVTViewController.h"
    
    @interface WVTViewController ()
    
    @end
    
    @implementation WVTViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        // Just load google.
        NSURL *theURL = [NSURL URLWithString:@"http://www.google.com"];
        NSURLRequest *request = [NSURLRequest requestWithURL:theURL];
        [self.myWebView loadRequest:request];
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        if (!self.didFirstLoad) {
            // Disable the default contextual menu.
            [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"];
        }
    }
    
    // Called by the gesture recognizer.
    - (IBAction)longPressDetected:(UILongPressGestureRecognizer *)sender
    {
        if (sender.state == UIGestureRecognizerStateBegan) {
    
            NSLog(@"Long press detected.");
    
            CGPoint webViewCoordinates = [sender locationInView:self.myWebView];
            NSLog(@"WebView coordinates are: %@", NSStringFromCGPoint(webViewCoordinates));
    
            // Find the DOM element
            NSString *locatorString = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).innerHTML", webViewCoordinates.x, webViewCoordinates.y];
            NSString *result = [self.myWebView stringByEvaluatingJavaScriptFromString: locatorString];
            NSLog(@"Element Found: %@", result);
    
        }
    
    }
    
    // Necessary or the gesture recognizer won't call the IBAction.
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    {
        return YES;
    }
    
    @end
    

    As I said, I tested the above code and it works fine. You can of course change up your JS and use something other than innerHTML, such as tagName or href or whatever you like. Multiple checks may be necessary for what you’re trying to do, possibly with queued JS commands (which would be lame), unless you could JSON-stringify the DOM object, pass it back to the Objective-C, convert to native objects and perform your checks in that environment–but, I’m no JS pro and I’m not going to investigate that.

    As a note, I was a bit surprised that the coordinates that worked for elementFromPoint were the touch coordinates within the UIWebView itself. I had rigged up a whole block of code that iterated through myWebView.scrollView.subviews and found the content view, then called locationOfTouch:inView: on that view. But I was getting funky behavior, so on a hunch I used the webview coordinates and it worked fine, even on a big webpage when I was scrolled off to the side and down. I suspect that some kind of Apple-programmed behavior inside the webview may translate those coordinates. Possibly the JS’s coordinate system is altered based on the way the content view is moved around inside the scrollview–that makes the most sense to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know how to get rid of the annoying tooltips that pop up
I'm looking for the way to get the direct link from mediafire. By default,
For my app, I'm trying to get the autocomplete suggestion box to pop up
I'm trying to get just a piece of information from Facebook, but I don't
my site page's goal is to get information from a fairly complex (but concise)
I want to get the computer user profile name to put log text on
I can't seem to find how to get the currently selected text from a
I want to make my system try icon to pop up a balloon message
I want to show the pop up of dynamic boxes.On each click i should
The default behaviour in browsers is to select the next form element. I want

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.