且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

(PHP)如何检测用户的计算机/浏览器处于暗模式?

更新时间:2022-04-21 21:50:44

由于PHP在服务器上执行时不了解客户端,因此没有直接的方法可以找到答案.

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

如果可以在JS中检测颜色模式,则可以将一个小的JS脚本嵌入到您的站点中,该脚本会设置一个cookie. Cookie是根据请求传输到服务器的,因此PHP可以查询它们.

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.