Windows应用商店应用(Windows 8.1)在WebView中未触发CoreWindow的CharacterReceived事件 [英] Windows Store App (windows 8.1) CharacterReceived event of CoreWindow is not triggered in WebView

查看:61
本文介绍了Windows应用商店应用(Windows 8.1)在WebView中未触发CoreWindow的CharacterReceived事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是 检测到的CharacterReceived事件 我们的Windows商店应用程序中的CoreWindow(内置于win 8.1)。 CharacterReceived 当我在其他页面中执行任何按键时触发事件。但是CharacterReceived 当
我从WebView执行任何按键时,不会触发事件。



如何解决此问题?任何人都可以为此提供任何解决方案吗?



谢谢。

解决方案

嗨PM16


>>如何解决这个问题? 


常见的解决方法是使用
InvokeScriptAsync < span style ="font-size:10.5pt; font-family:'Segoe UI',sans-serif; color:#454545">
使用JavaScript eval函数来使用HTML事件处理程序,并使用HTML事件处理程序中的window.external.notify来使用
WebView.ScriptNotify



WebView不支持从UIElement继承的大多数用户输入事件,例如KeyDown,KeyUp和CharacterReceived。
所以你需要使用window.external.notify将信息发送回你的应用程序并处理ScriptNotify事件以获取信息。


这是一个关于ScriptNotify的简单示例,您可以参考:


 public MyPage()
{
this.InitializeComponent();
MyWebView .ScriptNotify + = MyWebView_ScriptNotify;

//这里我们必须设置AllowedScriptNotifyUri属性,因为我们是
//导航到我们不拥有内容的某个网站,我们想要
//允许window.external.notify()将数据传回给app。
List< Uri> allowedUris = new List< Uri>();
allowedUris.Add(new Uri( " http://www.bing.com"));
MyWebView.AllowedScriptNotifyUris = allowedUris;
}

void MyWebView_ScriptNotify(object sender,NotifyEventArgs e)
{
//回复脚本通知。
}






有关详细信息,您可以看到此链接:

https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.webview#Remarks




最好的问候,


罗伊


Hi,

I am  detecting the CharacterReceived event of  CoreWindow in our windows store app(built in win 8.1). The CharacterReceived  event is triggered when i do any keypress in other pages. But CharacterReceived  event is not triggered when i do any keypress from WebView.

How to solve this? can anyone provide any solution for this ?

Thanks.

解决方案

Hi PM16

>>How to solve this? 

A common workaround is to use InvokeScriptAsync with the JavaScript eval function to use the HTML event handlers, and to use window.external.notify from the HTML event handler to notify the application using WebView.ScriptNotify.

WebView doesn’t support most of the user input events inherited from UIElement, such as KeyDown, KeyUp and CharacterReceived. So you need to use window.external.notify to send information back to your app and handle the ScriptNotify event to get the information.

Here is a simple sample about ScriptNotify that you could refer to:

public MyPage()
{
    this.InitializeComponent();
    MyWebView.ScriptNotify += MyWebView_ScriptNotify;

    // Here we have to set the AllowedScriptNotifyUri property because we are 
    // navigating to some site where we don't own the content and we want to 
    // allow window.external.notify() to pass data back to the app.
    List<Uri> allowedUris = new List<Uri>();
    allowedUris.Add(new Uri("http://www.bing.com"));
    MyWebView.AllowedScriptNotifyUris = allowedUris;
}

void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
    // Respond to the script notification.
}


For more information, you could see this link: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.webview#Remarks

Best regards,

Roy


这篇关于Windows应用商店应用(Windows 8.1)在WebView中未触发CoreWindow的CharacterReceived事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆