title: How to add parameter to image url with JavaScript
body: <p>I can embed images on my page with specified width and height (like this: <code>&lt;img src="image.php?w=100&amp;h=100"&gt;</code>)</p>
  
  <p>I want to load different image sizes depending on device screen width:
  100x100 for screen widths lower than 600px and 200x200 in other cases. As I understand php knows nothing about user screen so I have to use JS. </p>
  
  <p>This didn't work:</p>
  
  <pre><code>&lt;img src="image.php?&lt;script&gt;document.write('w=100&amp;h=100')&lt;/script&gt;"&gt;
  </code></pre>
  
  <p>That worked:</p>
  
  <pre><code>&lt;script&gt;document.write('&lt;img src="image.php?w=100&amp;h=100"&gt;')&lt;/script&gt;
  </code></pre>
  
  <p>Is that a correct way for doing this? Any consequences I should take into consideration? </p>