user1908746
user1908746

Reputation:

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.

So, how to detect WebView2 back and forward events?

Much appreciated.

Upvotes: 1

Views: 938

Answers (1)

user1908746
user1908746

Reputation:

@RezaAghaei provided the answer above.

Subscribing to the CoreWebView2.HistoryChanged event does the trick.

CoreWebView2.HistoryChanged

Note that, naturally, this must be done after CoreWebView2 has been initialized.

Subscribing to the CoreWebView2.SourceChanged event also works.

CoreWebView2.SourceChanged

Upvotes: 1

Related Questions