Jump to content

How to use window.innerWidth


Jiasheng

Recommended Posts

<script language="JavaScript"><!--if (navigator.appVersion.substring(0,1) >= 4) {    var width = window.innerWidth;    if (width > 900) { document.write("<link href='http://www.lomontimt.com/quotes/style1.css' rel='stylesheet' type='text/css'>"); }    else { document.write("<link href='http://www.lomontimt.com/quotes/style2.css' rel='stylesheet' type='text/css'>"); }}else { document.write("<link href='http://www.lomontimt.com/quotes/style1.css' rel='stylesheet' type='text/css'>"); }//--></script>

I set up the above Javascript to switch between two style sheets. User with screen resolution 1024x768 will be presented with style1.css, and those with smaller resolution will be presented with style2.css. But it seems that the parameter window.innerWidth is not working. Style sheet 2 is presented all the times regardless of the screen resolution. Appreciate very much if anyone could help me!

Link to comment
Share on other sites

try screen.width

<script language="JavaScript"><!--if (navigator.appVersion.substring(0,1) >= 4) {   var width = screen.width;   alert(width);   if (width > 900) { document.write("<link href='http://www.lomontimt.com/quotes/style1.css' rel='stylesheet' type='text/css'>"); }   else { document.write("<link href='http://www.lomontimt.com/quotes/style2.css' rel='stylesheet' type='text/css'>"); }}else { document.write("<link href='http://www.lomontimt.com/quotes/style1.css' rel='stylesheet' type='text/css'>"); }//--></script>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...