简体   繁体   English

如何检测 WebView2 前后事件?

[英]How to detect WebView2 back and forward events?

I have tried using scripts like...我尝试过使用类似...的脚本

window.addEventListener('hashchange', function()
{
    alert(1);
});

and...和...

window.addEventListener('popstate', function()
{
    alert(1);
});

... without luck. ......没有运气。

Note that initialization is done properly, other scripts work, navigation is fine, and this is WinForms .请注意,初始化已正确完成,其他脚本工作,导航很好,这是WinForms

So, how to detect WebView2 back and forward events?那么,如何检测 WebView2 的前后事件呢?

Much appreciated.非常感激。

@RezaAghaei provided the answer above. @RezaAghaei 提供了上面的答案。

Subscribing to the CoreWebView2.HistoryChanged event does the trick.订阅CoreWebView2.HistoryChanged事件就可以解决问题。

CoreWebView2.HistoryChanged CoreWebView2.HistoryChanged

Note that, naturally, this must be done after CoreWebView2 has been initialized.请注意,这自然必须在CoreWebView2初始化之后完成。

Subscribing to the CoreWebView2.SourceChanged event also works.订阅CoreWebView2.SourceChanged事件也可以。

CoreWebView2.SourceChanged CoreWebView2.SourceChanged

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM