IOS WKWebview有效實現禁止滑動,禁止雙指縮放,禁止長按

WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
config.preferences = [WKPreferences new];
config.preferences.minimumFontSize = 10;
config.preferences.javaScriptEnabled = YES;
config.preferences.javaScriptCanOpenWindowsAutomatically = YES;

//下方代碼,禁止縮放
WKUserContentController *userController = [WKUserContentController new];
NSString *js = @" $('meta[name=description]').remove(); $('head').append( '' );";
WKUserScript *script = [[WKUserScript alloc] initWithSource:js injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
NSMutableString *javascript = [NSMutableString string]; [javascript appendString:@"document.documentElement.style.webkitTouchCallout='none';"];//禁止長按
[javascript appendString:@"document.documentElement.style.webkitUserSelect='none';"];//禁止選擇
WKUserScript *noneSelectScript = [[WKUserScript alloc] initWithSource:javascript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[userController addUserScript:script];
[userController addUserScript:noneSelectScript];
[userController addScriptMessageHandler:self name:@"openInfo"];
config.userContentController = userController;

_webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];
_webView.scrollView.bounces = false;//禁止滑動
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章