View Full Version : Help with very simple js problem - auto resize page script

Jan 16th, 2010, 04:58 AM
i have this code included within a .php file on my website. I realised that my %age rules defining the width of my website page dont really work once i get to wider sizes so i want to use a fixed width page design using css code (only once wide enough) to achieve this. Please have a look at my code and tell me what im doing wrong i cant find anything wrong with my js. If js is anything like python i may need to change the output from a string to an integer or something along those lines. I can easily just doc.write the width but i cant get it to compare properly

<script type="text/javascript">
if (document.body.clientWidth > 1280)
{document.write('<link href="wdestyle.css" rel="stylesheet" type="text/css" />')};
{document.write('<link href="nrostyle.css" rel="stylesheet" type="text/css" />')};

Philip M
Jan 16th, 2010, 08:17 AM
To obtain with width of the monitor screen:-

<script type="text/javascript">
if (screen.width > 1280) {
document.write('<link href="wdestyle.css" rel="stylesheet" type="text/css" />')
else {
document.write('<link href="nrostyle.css" rel="stylesheet" type="text/css" />')

Bear in mind that the width of the monitor screen is not the same as the size of the browser window a visitor is using - windows can of course be set to different sizes.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.