How to add popup button in UIWebView

The deafult flash opens when I press the music play button at any URL from for a long time UIWebView. I want to add another button in a popup. Can this be done.

How I want to add a button FETCH.

And can I make changes to the default popup that is OPENand COPY. shown below

enter image description here

I find out that google is

First of all, you really cannot add additional menu items to the standard context menus. But you can disable the context menu using a specific CSS property. So the solution would be to disable the default menu and implement your own from scratch. And to implement your own context menu, you first need to 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 HTML elements in this place.

+5
source share
3 answers

NEW RESPONSE:

Looks like this is what we want here:

fooobar.com/questions/1131219 / ...

OLD RESPONSE:

Well, after some research, here's the deal:

What you describe in your question seems accurate:

, . CSS. , . , , , - , , HTML .

, popover - , , , , .

, , UIWebView -, DOM, , , popover-.

, :

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

JS, , , , , , , , , .

:

, UILongPressGestureRecognizer UIWebView ( ) , " " IBAction ViewController. ( , , .)

locationOfTouch:inView: , , , , , UIWebView, , , - myWebView.scrollView.subviews[0] ( objectAtIndex: variant, ).

, , , .


EDIT:

, , . , , , WebKit - "" DOM, , , , JS- elementFromPoint, , , , . .

" " UIWebView xib, delegate File Owner. a UILongPressGestureRecognizer xib, UIWebView. delegate selector longPressDetected IBAction File Owner. " " Interface Builder.

.

:

//
//  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

:

//
//  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

, , . , , JS - , innerHTML, tagName href, . , , , , JS ( ), JSON- DOM, Objective-C, - JS, .

, , elementFromPoint, UIWebView. , myWebView.scrollView.subviews, , locationOfTouch:inView: . , , webview, -, . , - Apple- webview . , JS , scrollview, .

+5

you can fire the event as follows:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
  if( navigationType == UIWebViewNavigationTypeLinkClicked )
  {
    // Handle your URL click here (open the popup menu)
    // ...
    return NO;
  }
  return YES;
}

don't forget to delegate UIWebView

0
source

All Articles