html - Changing src of Image by javascript, does not take effect in mobile devices -


i have written small javascript code screen dimensions of user browser. @ first, src attribute of img element set static image url. when page loaded, following code, calculate screen dimensions , send them server changing src of img contains dimensions uri parameters (later, @ server side, these parameters processed):

  <img id="screenres" src="http://static.example.com/image.jpg" alt="" width="20" height="20" />    <script>  window.onload=function(){      var w =math.round(screen.width);      var h =math.round(screen.height);      document.getelementbyid("screenres").src=                  "http://www.example.com/screen/"+w+"/"+h;   }   </script> 

this approach works in desktop browsers, mobile users fails. please tell me wrong in approach? thank beforehand suggestions overcome problem.

var w = math.max(document.documentelement.clientwidth, window.innerwidth || 0) var h = math.max(document.documentelement.clientheight, window.innerheight || 0)