目前的任务是将全屏模式的支持添加到用Dart编写的WebGL应用程序。
canvas.requestFullscreen()适用于简单的测试用例,但在完整的应用程序中失败。
请指出告诉阻止浏览器切换到全屏的方法。
代码是:
void trapFullscreenError() {
document.onFullscreenError.listen((e) {
log("fullscreenerror: $e");
});
}
void toggleFullscreen(CanvasElement c) {
log(
"fullscreenSupport=${document.fullscreenEnabled} fullscreenElement=${document.fullscreenElement}"
);
if (document.fullscreenElement != null) {
log("exiting fullscreen");
document.exitFullscreen();
} else {
log("requesting fullscreen");
c.requestFullscreen();
}
}
在Chrome中,代码会导致:
fullscreenSupport=true fullscreenElement=null
requesting fullscreen
fullscreenerror: Instance of 'Event'
Dartium调试器显示以下字段:
Event [id=4]
_selector null
bubbles true
cancelable false
clipboardData null
currentTarget #document [id=5]
defaultPrevented false
eventPhase 3
hashCode 234642739
path NodeList[6] [id=6]
target canvas#main_canvas [id=7]
timeStamp 1398779450832
type "webkitfullscreenerror"
答案 0 :(得分:4)
出于安全原因requestFullscreen
只能在键盘或点击事件的事件处理程序中调用。