Determine the screen resolution of the visitor's monitor through js and give prompts
First give a code example:
]
This code The general idea is to determine whether the modified image is suitable to be used directly as the visitor's desktop wallpaper by comparing the image resolution and the desktop resolution. Among them, 1920 and 1200 after fw="1920" and fh="1200" are the width and height parameters of the image respectively, which can be replaced by the actual image width and height parameters read by php and so on. In the past, I used if to make judgments before lines 11 and 12. Yesterday, after I increased the desktop resolution, I found that there would be two prompts - if the desktop resolution is greater than the image resolution, I would get an error after changing to else if parallel code. solve.
<script>
<!--
fw="1920";fh="1200";
var uw=window.screen.width;
var uh=window.screen.height;
if(fw==uw) {
if(fh==uh){document.write("<span class='green'>完全适合做您的桌面")}
else if(fh<uh){document.write("<span class='red'>不适合做您的桌面")}
else {document.write("<span class='yellow'>裁剪以后适合做您的桌面↘")}
}
else if(fw<uw){document.write("<span class='red'>尺寸略小,不适合做您电脑的桌布")}
else if(fw>uw){
if (fw/fh==uw/uh) {document.write("<span class='green'>适合做您的桌面")}
else {document.write("<span class='yellow'>不完全适合您的分辨率,您可以自己动手裁剪↘")}
}
-->
</script> In addition, I originally wanted to use the PHP method to pass the image width and height, but this requires using get to pass it in advance, or there will be a jump or even an infinite loop, so for the time being, I can only use JS to judge. Of course, there are also ways to combine js and php, but the effect is not very good.