admin管理员组文章数量:1345393
I was looking at the document.hidden
specs here to understand what exactly hidden entails:
- If steps to determine the visibility state return
visible
, then returnfalse
. 2. Otherwise, returntrue
.
Note
Support for
hidden
attribute is maintained for historical reasons. Developers should usevisibilityState
where possible.
visibilityState
is another property that can return one of three strings: 'visible'
, 'hidden'
, or 'prerender'
.
document.hidden
(as indicated by the above rules) returns true
for 'visible'
and false
for all other strings.
I am curious about the note. Why do they say that developers should prefer visibilityState
to hidden
?
Is it simply because visibilityState
gives you more "power" (re: granularity) in that it's more specific about what state the document is in, whereas hidden
dumbs it down by turning the four states into two states, "hidden" or "not hidden"?
I understand that this may only be answerable by the people who wrote the specs, but maybe they're crawling around here.
A preemptive note: I'm going to guess that this may be closed as "opinion-based", because it'll attract opinionated answers, and while it certainly may attract answers like that, this can be answered objectively by those who wrote the specs, so I'll take my chances.
I was looking at the document.hidden
specs here to understand what exactly hidden entails:
- If steps to determine the visibility state return
visible
, then returnfalse
. 2. Otherwise, returntrue
.
Note
Support for
hidden
attribute is maintained for historical reasons. Developers should usevisibilityState
where possible.
visibilityState
is another property that can return one of three strings: 'visible'
, 'hidden'
, or 'prerender'
.
document.hidden
(as indicated by the above rules) returns true
for 'visible'
and false
for all other strings.
I am curious about the note. Why do they say that developers should prefer visibilityState
to hidden
?
Is it simply because visibilityState
gives you more "power" (re: granularity) in that it's more specific about what state the document is in, whereas hidden
dumbs it down by turning the four states into two states, "hidden" or "not hidden"?
I understand that this may only be answerable by the people who wrote the specs, but maybe they're crawling around here.
A preemptive note: I'm going to guess that this may be closed as "opinion-based", because it'll attract opinionated answers, and while it certainly may attract answers like that, this can be answered objectively by those who wrote the specs, so I'll take my chances.
Share Improve this question edited May 11, 2021 at 22:07 pushkin asked Jun 13, 2018 at 22:01 pushkinpushkin 10.3k16 gold badges63 silver badges107 bronze badges 5-
As an update to this question, where you mention the four
visibilityState
possible values, I would like to note that the'unloaded'
value has bee deprecated and thus only three possible values for this property remain. – Robin Bastiaan Commented May 11, 2021 at 21:23 - @RobinBastiaan Thanks, edited it – pushkin Commented May 11, 2021 at 22:07
- 1 Some discussion: github./w3c/page-visibility/issues/63 – Kaiido Commented May 11, 2021 at 23:13
- @Kaiido Thanks! looks like this note about not using hidden was since removed. Would you like to post an answer? – pushkin Commented May 12, 2021 at 0:05
- Three years later, it looks like there are now only two possible values for visibilityState, 'visible' and 'hidden'. See same link to MDN docs for visibilityState by OP – Eric D'Souza Commented Aug 7, 2024 at 14:31
2 Answers
Reset to default 7The notice of hidden
being maintained for historical reasons has been removed in this PR.
There is some discussion here about this change.
I did not write the specification, but I would assume you are correct -- the introduction of visibilityState
made hidden
obsolete. hidden
does nothing that visibilityState
doesn't do better. It is likely on the road to deprecation, given their insistence that you use the latter.
本文标签: javascriptWhy are we supposed to prefer documentvisibilityState to documenthiddenStack Overflow
版权声明:本文标题:javascript - Why are we supposed to prefer document.visibilityState to document.hidden? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743805467a2542098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论