Determine the screen resolution of a visitor's monitor using js and give tips _ javascript skills

Source: Internet
Author: User
The purpose of this Code is to compare the image resolution and desktop resolution to determine whether the modified image is suitable for use as a visitor's desktop wallpaper. Through js, the screen resolution of the visitor's display is determined and a prompt is given.


First, the code example is provided:

Script <! -- Fw = "1920"; fh = "1200"; var uw = window. screen. width; var uh = window. screen. height; if (fw = uw) {if (fh = uh) {document. write ("perfect for your desktop")} else if (fh <uh) {document. write ("not suitable for your desktop")} else {document. write ("suitable for your desktop after cropping")} else if (fw <uw) {document. write ("slightly smaller size, not suitable for making your computer's tablecloth")} else if (fw> uw) {if (fw/fh = uw/uh) {document. write ("suitable for your desktop")} else {document. write ("not perfect for your resolution, you can cut it by yourself")} --> script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]



The purpose of this Code is to compare the image resolution and desktop resolution to determine whether the modified image is suitable for use as a guest's desktop wallpaper. The 1920 and 1200 parameters after fw = "1920" and fh = "1200" are respectively the width and height parameters of the image. They can be replaced by the actual image width and height parameters read by php. In the past, I used the if statements before 11th and 12 rows. After I increased the desktop resolution yesterday, I found two tips-if the desktop resolution is greater than the image resolution, after changing to else if parallel code, the error is solved.

In addition, I wanted to use the PHP method to transmit the image width and height. However, in this case, get should be used to deliver the image in advance, or there may be a jump or even an endless loop. So for the moment, I can only use JS to determine the image width and height. Of course, there are also methods of combining js and php, which are not very effective.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.