Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get the viewport size, you must use Javascript, yes. For examples of code doing that (not always easy, there are differences between browsers), you can take a look at how JS Frameworks/Libraries determine that size (for instance, in prototype.js, there is a <a href="http://www.prototypejs.org/api/document/viewport/getDimensions" rel="nofollow noreferrer">getDimensions</a> function that does what you want) ; google will get you lots of results about that too (<a href="http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/" rel="nofollow noreferrer">this one</a> is an example of those results)</p> <p>Then, you must send that size to PHP. For that, two solutions :</p> <ul> <li>One is to use an Ajax request (sending the width and height as parameters)</li> <li>The other is to dynamically build an <code>&lt;img&gt;</code> tag, with an URL pointing to the PHP script, like <code>'http://.../size.php?w=WIDTH&amp;h=HEIGHT'</code> <ul> <li>many statistic software (things like xiti / google analytics -- not sure if those ones do ^^ ) use that kind of method.</li> </ul></li> </ul> <p>In the second case, the JS code could look like this :</p> <pre><code>&lt;script type="text/javascript"&gt; var width = 100; var height = 80; var tag = document.createElement('img'); // Create the tag tag.src = 'http://tests/temp/viewport/size.php?'; tag.src += 'w=' + width; // Pass the size tag.src += '&amp;h=' + height; document.body.appendChild(tag); // Insert the tag into the page &lt;/script&gt; </code></pre> <p>And then, in size.php, you use $_GET['w'] and $_GET['h']. Note : you will probably have to return some valid image data from size.php, to not get a "red cross" picture (a transparent gif, 1x1 in size, for instance, will do the trick)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload