Javascript-js How to get screensize variable to PHP to invoke different images?

Source: Internet
Author: User
Keywords javascript php
Web site want to make adaptive, PHP will automatically generate the different size of the summary thumbnail, but PHP has no way to get the user screen size, only by JS to get, JS get into PHP data is a string type, with (int) intval () can not be converted to an integer, can not do a numerical comparison, Solution ~ ~


  
    1600) {    //调用1600宽的图片} elseif ($sw_int > 1000) {    //调用1000宽的图片} else {    //调用800宽的图片}?>

Reply content:

Web site want to make adaptive, PHP will automatically generate the different size of the summary thumbnail, but PHP has no way to get the user screen size, only by JS to get, JS get into PHP data is a string type, with (int) intval () can not be converted to an integer, can not do a numerical comparison, Solution ~ ~


  
    1600) {    //调用1600宽的图片} elseif ($sw_int > 1000) {    //调用1000宽的图片} else {    //调用800宽的图片}?>

This is usually not the case, PHP generates different sizes of thumbnails to be static, and the thumbnail name should be regular, such as Image_0153431242_small.jpg, Image_0153431242_middle.jpg, Image_ 0153431242_big.jpg, image_0153431242_source.jpg this.
So the front-end JS as long as the adjustment is good, rather than pass to PHP processing, for example

This format does not easily handle browser-side caching, which affects the speed at which pages are opened two times.

In addition, you may not understand how PHP works. For PHP, JS is just a string that is processed and exported by PHP, that is, when the JavaScript code executes, the PHP process is already closed. PHP runs on the server side, JS runs on the browser side, and the two cannot interact at any time.

Own Baidu a bit srcset this label, Zhang Xin Xu has a few talk about this

  • 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.