Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WebView中使用InvokeScript处理JS事件_C#_Javascript_Windows 8_Webview_Winrt Xaml - Fatal编程技术网

C# 如何在WebView中使用InvokeScript处理JS事件

C# 如何在WebView中使用InvokeScript处理JS事件,c#,javascript,windows-8,webview,winrt-xaml,C#,Javascript,Windows 8,Webview,Winrt Xaml,为了让C#从WebView中提取信息或对事件做出反应,我们使用InvokeScript。但是,InvokeScript似乎没有将属性附加到事件。怎么了 private void WebView_LoadCompleted(object sender, NavigationEventArgs e) { var _WebView = sender as WebView; _WebView.AllowedScriptNotifyUris = WebView.AnyScriptNotif

为了让C#从WebView中提取信息或对事件做出反应,我们使用InvokeScript。但是,InvokeScript似乎没有将属性附加到事件。怎么了

private void WebView_LoadCompleted(object sender, NavigationEventArgs e)
{
    var _WebView = sender as WebView;
    _WebView.AllowedScriptNotifyUris = WebView.AnyScriptNotifyUri;
    _WebView.AllowedScriptNotifyUris.Add(e.Uri);

    // test1 fires immediately
    _WebView.InvokeScript("execScript", new[] { "window.external.notify('test1'); " });

    // test2 never fires
    _WebView.InvokeScript("execScript", new[] { "document.addEventListener = function (e) { window.external.notify('test2'); }" });

    // test3 never fires
    _WebView.InvokeScript("execScript", new[] { "function x(e) { window.external.notify('test3'); } document.addEventListener('onmousedown', x);" });

}

private void WebView_ScriptNotify(object sender, NotifyEventArgs e)
{
    // listen for external.notify event
    System.Diagnostics.Debugger.Break();
}

我觉得这不像javascript。更多的c#?@IanOverton你需要阅读实际问题。
\u WebView.InvokeScript(
是javascript。
document.addEventListener=function(e){window.external.notify('test2');}
您是否有意重写
addEventListener
?我认为应该是
document.onmousedown=function…
window.onmousedown=function…