开发者

Is it safe to use window.screen?

开发者 https://www.devze.com 2023-04-03 02:05 出处:网络
MDN explains how to use the window.screen object, but also says \"DOM Level 0. Not part of specification.\"

MDN explains how to use the window.screen object, but also says "DOM Level 0. Not part of specification."

W3Schools says that window.screen.* properties are supported in all major browsers.

If I understand this correctly... window.screen is completely non-standard, but is nonetheless universally supported. Is that right?

If this is the case, are there any cross-browser differences I need to be aware of, or can I just use it? I'm mostly interested in screen.availWidth, by t开发者_如何学编程he way.


Quirksmode compatibility tables to the rescue!

http://www.quirksmode.org/dom/w3c_cssom.html#screenview

Most, but not all values are supported by the major browsers.


You should be fine with it.

The reason that it is not part of a standard is because DOM Level 0 was introduced before standards were around. DOM Level 0 is also called the Legacy DOM, and it was created at the same time NetScape 2.0 made JavaScript in the browser a reality; in effect, DOM Level 0 was the very first DOM spec.

The Legacy DOM will be around for a long time, if not then it would break backward compatibility with a TON of very popular scripts already in existence.

EDIT: In other words, your understanding is completely correct. It is not "standardized" but it is completely universal and will remain so for a long time.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号