C#InvokeScript给出错误80020006

本文关键字:80020006 错误 出错 C#InvokeScript | 更新日期: 2023-09-27 18:21:11

我有一段代码如下。

webBrowser.IsScriptEnabled = true;
webBrowser.InvokeScript("eval", "alert('hey')");

给出了CCD_ 1。你能指导如何纠正这个错误吗。

C#InvokeScript给出错误80020006

Windows Phone中没有内置浏览器window.alert,但您可以按如下方式绑定一个浏览器来调用WebBrowser.ScriptNotify

//inside the page
window.alert = function (__msg) { window.external.notify(' + __msg + '); };

// in your C# code
this.webBrowser.ScriptNotify += new EventHandler<NotifyEventArgs>(Browser_ScriptNotify);
void Browser_ScriptNotify(object sender, NotifyEventArgs e)
{
     MessageBox.Show(e.Value);
}
//later 
this.CordovaView.Browser.IsScriptEnabled = true;
this.CordovaView.Browser.InvokeScript("alert", "ok");

在Cordova上,还有一个通知插件,您可以通过插入

window.alert = navigator.notification.alert;

只需确保在config.xml 中启用通知插件

  <feature name="Notification">
      <param name="wp-package" value="Notification"/>
  </feature>

这是由竞赛条件引起的。我们需要做的是

this.CordovaView.Browser.LoadCompleted+=浏览器_LoadCompleted;

然后

  void Browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
    {
        this.CordovaView.Browser.IsScriptEnabled = true;
        this.CordovaView.CordovaBrowser.IsScriptEnabled = true;
        this.CordovaView.Browser.InvokeScript("setPushToken", push_uri);
    }