Determine the screen resolution of the guest monitor through JS and give a hint

Source: Internet
Author: User
Tags php and
This code is intended to determine whether the image is suitable for use as a guest's desktop wallpaper by comparing the resolution of the picture and the resolution of the desktop

Determine the screen resolution of the guest monitor through JS and give a hint


First give the code example:

<textarea id="runcode51847"><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 ' > is perfectly fit for your desktop </span>")} else if (Fh<uh) { document.write ("<span class= ' red ' > not suitable for your desktop </span>")} else {document.write ("<span class= ' yellow ' > Cropping is suitable for your desktop ↘</span> ")}} else if (FW<UW) {document.write (" <span class= ' red ' > size is slightly smaller, not suitable for your computer's tablecloth </span >} else if (FW>UW) {if (Fw/fh==uw/uh) {document.write ("<span class= ' green ' > Fit to do your desktop </span>")} else { document.write ("<span class= ' yellow ' > does not exactly fit your resolution, you can cut it Yourself ↘</span>")}}--> </script></textarea>


[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]



This code is intended to determine whether the change is appropriate for a desktop wallpaper that is directly used as a visitor by comparing the resolution of the picture with the desktop resolution. Where the fw= "1920" and Fh= "1200" after 1920, 1200 are the width of the picture and height parameters, can be read in PHP and other actual picture width and height parameters instead. Before the 11th, 12 lines before the judge I used to use if, yesterday when the desktop resolution to see that there will be 2 tips-if the desktop resolution is larger than the picture resolution, replaced by if the other if parallel code after the error resolution.

You would otherwise want to use the method of PHP to pass picture width and height, but in order to use get advance delivery, or jump or even death cycle, so temporarily only with JS to judge. Of course, there are JS and PHP combination of methods, the effect is not very good.

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.