Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

javascript - onfullscreenchange DOM event

as the title reads, I'd like to know what is the most reliable way to trigger an event when the Browser(s) enters/leaves in/out the fullscreen mode.

note : I'm not asking how to fullscreen the current page, I just want to know whether or not there is a way to queue some tasks if the user, for example, press F11 or any other related fullscreen-entering keys.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I was working with this event when I stumble with this question, I want to share what I learn about it even though it won't solve this question. The onfullscreenchange event is now supported with prefixes by modern desktop browsers and Chrome for Android, but there are some things to have in mind:

  • This event won't trigger when the window goes fullscreen, I know it sounds weird, but it seems to be intended only for the document and its elements. So if an element of a document goes fullscreen the event will trigger, but when a keyboard shortcut is used to make your browser fullscreen it won't.

  • In Chrome and Safari a function can subscribe to this event either by defining the document method document.onwebkitfullscreenchange = myFunc; or by defining the element method myElem.onwebkitfullscreenchange = myFunc;, also you can use addEventListener myElem.addEventListener("webkitfullscreenchange", myFunc);. In IE and Firefox the event will work only if the method is defined in the document and using addEventListener won't trigger the event.

Here's a Codepen Demo of this event, more info in MDN Using fullscreen mode.


Update. From MDN web docs:

For the moment not all browsers are implementing the unprefixed version of the API (for vendor agnostic access to the Fullscreen API you can use Fscreen).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...