iOS WKWebView的javascript alert 不弹的解决方案
2018-01-04 09:41
525 查看
这个文章只针对h5使用系统的alert弹框,对自定义的弹框,是不需要写的
实现这3个方法,直接复制粘贴,不需要修改,就可以了
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message?:@"" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:([UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { completionHandler(); }])]; [self presentViewController:alertController animated:YES completion:nil]; } - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler{ // DLOG(@"msg = %@ frmae = %@",message,frame); UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message?:@"" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:([UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { completionHandler(NO); }])]; [alertController addAction:([UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { completionHandler(YES); }])]; [self presentViewController:alertController animated:YES completion:nil]; } - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable))completionHandler{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:prompt message:@"" preferredStyle:UIAlertControllerStyleAlert]; [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.text = defaultText; }]; [alertController addAction:([UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { completionHandler(alertController.textFields[0].text?:@""); }])]; [self presentViewController:alertController animated:YES completion:nil]; }
实现这3个方法,直接复制粘贴,不需要修改,就可以了
相关文章推荐
- iOS WKWebView的javascript alert 不弹的解决方案
- iOS中UIWebView与WKWebView、JavaScript与OC交互、Cookie管理看我就够(中)
- WKWebViewJavascriptBridge 在iOS 11上的问题
- iOS开发-------基于WKWebView的原生与JavaScript数据交互
- iOS用WKWebView与JS交互获取系统图片及WKWebView的Alert,Confirm,TextInput的监听代理方法使用,屏蔽WebView的可选菜单
- ios wkwebview离线化加载h5资源解决方案
- iOS下JS与OC互相调用(六)--WKWebView + WebViewJavascriptBridge
- iOS-js与iOS的交互(基于WKWebViewJavascriptBridge第三方)
- iOS中UIWebView与WKWebView、JavaScript与OC交互、Cookie管理看我就够(下)
- IOS之JavaScript与OC的相互调用:WKwebview 的使用
- iOS中UIWebView与WKWebView、JavaScript与OC交互、Cookie管理看我就够(上)
- iOS下JS与OC互相调用(六)--WKWebView + WebViewJavascriptBridge
- iOS下JS与OC互相调用(六)--WKWebView + WebViewJavascriptBridge
- iOS用WKWebView与JS交互获取系统图片及WKWebView的Alert,Confirm,TextInput的监听代理方法使用,屏蔽WebView的可选菜单
- iOS下JS与OC互相调用(六)-->WKWebView + WebViewJavascriptBridge
- iOS 8 WkWebView 网页的配置和前进,后退,js 交互和进度条的加载
- [iOS] 使用WebViewJavascriptBridge实现OC与JS交互
- 浅谈iOS中WKWebView和UIWebView的清除缓存问题
- ios js与oc原生WKWebView方法注入及交互传值
- iOS 给webView加进度条(WKWebView)