How to programmatically exit full screen mode in WebView?

So, let's say, I opened the html5 video in full screen mode (after which WebView lifted ContainsFullScreenElementChangedand it is ContainsFullScreenElementnow right). How can I programmatically exit it?

I connect to SystemNavigationManager.GetForCurrentView().BackRequestedand want to exit full-screen mode if it is present and call WebView.GoBack () if it is not.

WebView has no associated method, and the ApplicationView class does not help either.

+4
source share
1 answer

So, after searching a few more, I found a solution.

HTML5 fullscreen api, . , InvokeScriptAsync WebView. , :

string[] args = {
    @"if (document.exitFullscreen) {
        document.exitFullscreen();
      }
      else if (document.msExitFullscreen) {
        document.msExitFullscreen();
      }"
};

await CurrentWebView.InvokeScriptAsync("eval", args);

- , , .

, InvokeScriptAsync BackRequested, , BackRequestedEventArgs.Handled true , , , , .

EDIT: , script Anniversary Update ( 14393). , webkit, . - ( webkit):

string[] args = {
    @"if (document.exitFullscreen) {
        document.exitFullscreen();
    } else if (document.msExitFullscreen) {
        document.msExitFullscreen();
    } else if(document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
    }"
};
+3

Source: https://habr.com/ru/post/1625090/


All Articles