2016-01-20 84 views
4

假设我以全屏模式打开了html5视频(此后WebView提出了ContainsFullScreenElementChanged,现在它的确是ContainsFullScreenElement)。我怎样才能以编程方式退出它?如何在WebView中以编程方式退出全屏模式?

我连接到SystemNavigationManager.GetForCurrentView().BackRequested并希望退出全屏模式,如果它存在,并调用WebView.GoBack(),如果它不是。

WebView没有任何相关的方法,ApplicationView类也没有帮助。

回答

3

好的,所以在搜索了一些之后,我找到了一个解决方案。

HTML5有fullscreen api,它可用于要求全屏或退出它。您可以使用WebView的InvokeScriptAsync方法来运行它。在我的具体情况我结束了类似下面的代码:

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

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

第一句话居然是什么对我的作品,但我离开,以防万一第二个。

哦顺便说一句,如果你在BackRequested处理程序调用InvokeScriptAsync像我一样,你可能会想你怎么称呼它之前设置BackRequestedEventArgs.Handled为true ,因为这是一个异步方法和事件将进一步传递到未处理的其他用户,这可能会导致不良行为。

编辑:似乎这个脚本不能在周年纪念更新(建立14393)。但是,如果您再添加一个带有webkit前缀的检查,它将起作用。像这样的东西(或者你可以留下一个带有webkit前缀的单一支票):

string[] args = { 
    @"if (document.exitFullscreen) { 
     document.exitFullscreen(); 
    } else if (document.msExitFullscreen) { 
     document.msExitFullscreen(); 
    } else if(document.webkitExitFullscreen) { 
     document.webkitExitFullscreen(); 
    }" 
}; 
相关问题