您可以使用screen
对象来检测设备的屏幕分辨率。以下是JavaScript代码示例:
// 获取屏幕宽度
var screenWidth = window.screen.width;
// 获取屏幕高度
var screenHeight = window.screen.height;
// 输出屏幕分辨率
console.log("屏幕分辨率:" + screenWidth + " x " + screenHeight);
在上面的代码中,我们使用window.screen.width
获取屏幕宽度,使用window.screen.height
获取屏幕高度。最后,我们将屏幕分辨率输出到控制台中。