来自<webview>的警报对话框被阻止

时间:2015-05-30 17:26:40

标签: javascript webview dart google-chrome-app

当我使用网页浏览时,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 version = STABLE build 45396

     

SDK的版本号= 1.10.0

webview加载一个可以在我不创建的js上运行的页面。

使用此错误时会发生错误:

alert("***")

2 个答案:

答案 0 :(得分:4)

默认情况下,网页视图无法显示。

你需要抓住dialog event,为它显示你自己的用户界面(请记住,应用can't use alert and friends,所以NSDictionary是一个不错的选择)然后用{传递回复{3}}

答案 1 :(得分:3)

关于@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