Add script if window is wider than 480 pixel - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window Load

Description

Add script if window is wider than 480 pixel

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/* w w  w .j  ava 2s . c o m*/
var swidth = (window.innerWidth > 0) ? window.innerWidth : screen.width;
if (swidth > 480) {
    var s = document.createElement("script");
    s.type = "text/javascript";
    s.src = "http://your server .js";
    document.getElementsByTagName('head')[0].appendChild(s);
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials