WKWebview里 javascript alert 不彈的解決方案

- (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:@"確認(rèn)" 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{

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message?:@"" preferredStyle:UIAlertControllerStyleAlert];

[alertController addAction:([UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

completionHandler(NO);

}])];

[alertController addAction:([UIAlertAction actionWithTitle:@"確認(rèn)" 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];

}

添加以上三個(gè)方法

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 前言: web頁(yè)面和app的直接的交互是很常見的東西,在ios8之前,用的是uiwebview,但是在ios8之后...
    qingchen91閱讀 3,075評(píng)論 6 25
  • 一、實(shí)現(xiàn)WKUIDelegate的意義 1. 防止網(wǎng)頁(yè)內(nèi)容在遇到__blank標(biāo)簽時(shí)不響應(yīng)點(diǎn)擊的bug2. 使We...
    Sweet丶閱讀 1,286評(píng)論 0 0
  • iOS8以后,蘋果推出了新框架Wekkit,提供了替換UIWebView的組件WKWebView。各種UIWebV...
    陌上北辰閱讀 681評(píng)論 0 0
  • 公司開始讓做一個(gè)新iOS項(xiàng)目,由于蘋果的更新需要每次發(fā)版本審核,沒法像服務(wù)器一樣實(shí)時(shí)更新,技術(shù)部就討論出原生+HT...
    奶茶007閱讀 1,871評(píng)論 16 9
  • //www.jb51.net/article/41725.htm 首先,為了在我們的程序中使用string類型,我...
    Trsfroid閱讀 462評(píng)論 0 0

友情鏈接更多精彩內(nèi)容