Return to Snippet

Revision: 41494
at February 19, 2011 03:18 by HelloKit


Updated Code
var iDevice = '';
if (/iPhone/.test(navigator.userAgent) || /iPod/.test(navigator.userAgent)) {
  iDevice = ' iphone';
} else if (/iPad/.test(navigator.userAgent)) {
  iDevice = ' ipad';
}
var myWidth = 0;
if( typeof( window.innerWidth ) == 'number' ) {
  //Non-IE
  myWidth = window.innerWidth;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  //IE 6+ in 'standards compliant mode'
  myWidth = document.documentElement.clientWidth;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  //IE 4 compatible
  myWidth = document.body.clientWidth;
}
document.write("<DIV ID=\"page");
if (myWidth>1024) {
  if (myWidth>1280) {
    document.write("-over-1280");
  }
  document.write("\" CLASS=\"highres");
}
else {
  document.write("\" CLASS=\"lowres");
}
document.write(iDevice);
document.write("\"><DIV ID=\"header\"><A HREF=\"/\"><IMG ID=\"masthead\" SRC=\"/");
if (myWidth>1152) {
  document.write("1280");
}
else if (myWidth>1024) {
  document.write("1152");
}
else if (myWidth>800) {
  document.write("1024");
}
else if (myWidth>640) {
  document.write("800");
}
else {
  document.write("640");
}
document.write(".png\" ALT=\"confoozled.com\"></A></DIV>");

Revision: 41493
at February 19, 2011 03:15 by HelloKit


Initial Code
var iDevice = '';
  if (/iPhone/.test(navigator.userAgent) || /iPod/.test(navigator.userAgent)) {
    iDevice = ' iphone';
  } else if (/iPad/.test(navigator.userAgent)) {
    iDevice = ' ipad';
  }
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
document.write("<DIV ID=\"page");
if (myWidth>1024) {
  if (myWidth>1280) {
    document.write("-over-1280");
  }
  document.write("\" CLASS=\"highres");
}
else {
  document.write("\" CLASS=\"lowres");
}
document.write(iDevice);
document.write("\"><DIV ID=\"header\"><A HREF=\"/\"><IMG ID=\"masthead\" SRC=\"/");
if (myWidth>1152) {
  document.write("1280");
}
else if (myWidth>1024) {
  document.write("1152");
}
else if (myWidth>800) {
  document.write("1024");
}
else if (myWidth>640) {
  document.write("800");
}
else {
  document.write("640");
}
document.write(".png\" ALT=\"confoozled.com\"></A></DIV>");

Initial URL


Initial Description
Also selects different sized header images for better image quality.

Initial Title
Detect iPhone/iPad, window resolution and setup CSS classes

Initial Tags
iphone

Initial Language
JavaScript