[英]Alert dialog from <webview> was blocked
當我使用webview並顯示此錯誤時,Dart不顯示警告對話框:
:已阻止警報對話框。 (擴展:: webViewEvents:225)
:確認對話框被阻止。 (擴展:: webViewEvents:225)
有誰知道如何繞過問題或如何捕獲錯誤?
謝謝。
對不起,我的英語不好。
編輯
使用的代碼:
Element webview= querySelector("#webview");
Map<String,String> map=new Map();
map["src"]=urlWebView;
webview.attributes.addAll(map);
webview.style.visibility="visible";
DartEditor版本= STABLE build 45396
SDK的版本號= 1.10.0
webview加載一個頁面,該頁面適用於我不創建的js。
使用此時發生錯誤:
alert("***")
默認情況下,webview無法顯示這些內容。
您需要捕獲dialog
事件 ,為它顯示您自己的UI(請記住,應用程序無法使用alert
和朋友 ,因此<dialog>
是一個不錯的選項)然后使用DialogController
傳回響應
更多關於@Xan的澄清答案:
你需要從webview中聽取對話框事件,請閱讀代碼中的注釋以便更好地理解,我再次使用nwjs,這樣你就可以用你的語言實現類似的版本:
//lets listen to alert dom and enable it
webview.addEventListener('dialog',function(e){
//message type
messageType = e.messageType;
messageText = e.messageText;
DialogController = e.dialog;
//lets checki if alert
if(messageType == 'alert'){
window.alert(messageText);
}//emd if
//if confirm
else if(messageType == 'confirm'){
//confirm
var confirm = window.confirm(messageText);
//get confirm bool and send to controller
if(confirm == true){
//if true send okay to browser
DialogController.ok();
}else{
//send cancel with to send false false
DialogController.cancel();
}//end if
}//end if confirm
//lastly if its prompt
else if(messageType == 'prompt'){
//get user Input
promptInput = window.prompt(messageText);
//if null , then means the user clicked cancel
if(promptInput == null){
//tell browser to cancel
DialogController.cancel();
}else{
//feed browser with input data
DialogController.ok(promptInput);
}
}//end if prompt
});//end dialog test
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.