IOS WKWebview ban long press (hyperlinks, images, text,…)

IOS WKWebview ban long press (hyperlinks, images, text,...)
selected style

What the. This is not what we want ~

IOS WKWebview ban long press (hyperlinks, images, text,...)

Recently, the company desperately urge progress, we decided to use web behind, in fact, my heart is not willing to volunteer in the United States to build a better home Native

These people seem to “burst effect of slag. We must get rid of the new WKWebview for Apple dad UiWebview solutions do not fully enjoy, in turn to turn to the WKWebview header file not found off. But I found this in the configuration information WKWebViewConfiguration header file we can add some of their own script

@abstract Adds a user / *! Script. @param userScript The user script to add. * / - (void) addUserScript: (WKUserScript * userScript);

We can add some scripts to this user configuration, which inspires me

- (WKWebView *) webView{if (! _webView) {/ / create a WKWebview configuration object WKWebViewConfiguration*config = [[WKWebViewConfiguration alloc] init] = [[WKPreferences alloc]; config.preferences init]; config.preferences.minimumFontSize =10; config.preferences.javaScriptEnabled =YES; config.preferences.javaScriptCanOpenWindowsAutomatically =NO; NSMutableString *javascript = [NSMutableString string]; [javascript appendString:@'none'; "]; / /'none' [javascript appendString:@ according to the prohibition of long"; "]; WKUserScript *noneSelectScript = [[WKUserScript / ban alloc] initWithSourc E:javascript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES] webView WKWebView *webView; / / create = [[WKWebView alloc]initWithFrame:[UIScreen mainScreen].bounds configuration:config] [webView.configuration.userContentController addUserScript:noneSelectScript]; webView.UIDelegate; webView.navigationDelegate = self; self = webView.backgroundColor; [UIColor = whiteColor]; webView.scrollView.scrollEnabled = YES; [webView addObserver:self forKeyPath:@ "estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; _webView = webView;} return _webView;}

JS can also be executed directly, so that after the completion of the loading and so on

- (void) webView: (WKWebView * webView) didFinishNavigation: (WKNavigation *) navigation{[self.webView evaluateJavaScript:@ "'none';" completionHandler:nil] [self.webView evaluateJavaScript ":@;'none'; completionHandler:nil];}

SO.. Just get a little happy, get the long press the picture and then pop up this path, I went to

IOS WKWebview ban long press (hyperlinks, images, text,...)
hyperlink pop-up dialog box

Searched blog no solution to stack overflow on luck, the original apple will do in HTML to optimize the herf keyword, even if you href= “or” void href= # “(0)” will trigger the dialog
so two solutions to 1 in a HTML tag to completely remove href=xx

IOS WKWebview ban long press (hyperlinks, images, text,...)

2 if you need a business logic, you may wish to add a label instead of href

A.OriginalLink {color: blue; text-decoration: pointer;} < a class= "originalLink" onclick= "location.href='http://mylink';" > Real URL Link< /a> cursor; article: