(PHP) How to detect that user's computer/browser is in Dark Mode?

↘锁芯ラ 提交于 2020-01-30 09:01:06

问题


Lately I am updating my software to support dark mode, in response to research that looking at a paper-white background display is bad for the eyes and for sleep rhythms. Is there a way to detect from PHP that a user's browser and/or OS are set to Dark Mode? How about detecting that it is set to nighttime mode (reduction of blue colors)?


回答1:


Since PHP executes on the server without any knowledge of the client, there is no direct way of finding this out.

If it is possible to detect the color mode in JS, you could embed a small JS script to your site, that sets a cookie. Cookies are transmitted to the server on request, so PHP is able to query them.



来源:https://stackoverflow.com/questions/52388490/php-how-to-detect-that-users-computer-browser-is-in-dark-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!