Home > Web Front-end > JS Tutorial > body text

Determine the screen resolution of the visitor's monitor through js and give prompts_javascript skills

WBOY
Release: 2016-05-16 17:28:42
Original
1237 people have browsed it

Determine the screen resolution of the visitor's monitor through js and give prompts


First give a code example:


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]


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.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!