Background From Screen Resolution

[Total: 0    Average: 0/5]

This script loads different background colors/images based on viewer’s screen resolution.

Body Code:

<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from old browsers that do not support JavaScript.
// Feel free to copy and modify this script, but please keep the comment lines!
///////////////////////////////////////////////////////////////////////////////
// Function:    To set different backgrounds based on screen resolution.     //
// Application: There are times that you want different background images for//
//              different screen resolutions. Replace the 'bgcolor="#rrggbb"'//
//              with different 'background="image_name.xxx"' in 'body' tag in//
//              the following 'case' statements.                             //
//              Remember not to put any 'body' tag in the main HTML section. //
///////////////////////////////////////////////////////////////////////////////
// Hamid F. Fard    PetaNet Information Technology    http://www.petanet.com //
///////////////////////////////////////////////////////////////////////////////

  var ScrnSize = "UnCommon"

  if (navigator.appVersion.indexOf("4.") != -1 && 
      navigator.appName.indexOf("Explorer") != -1) {
     ScrnSize = screen.width + "x" + screen.height;
  }
  if (navigator.appVersion.indexOf("4.") != -1 && 
      navigator.appName.indexOf("Netscape") != -1) {
     ScrnSize = screen.width + "x" + (screen.height + 19); //Netscape sees 19 pixels less on Height
  }
  switch(ScrnSize) {
    case "640x480":   document.write('<body bgcolor="#FF0000" text="#000000">');
    case "800x600":   document.write('<body bgcolor="#00FF00" text="#000000">');
    case "1024x768":  document.write('<body bgcolor="#0000FF" text="#000000">');
    case "1152x864":  document.write('<body bgcolor="#FFFF00" text="#000000">');
    case "1280x1024": document.write('<body bgcolor="#AA0000" text="#000000">');
    case "1600x1200": document.write('<body bgcolor="#FF00FF" text="#000000">');
    case "1600x1280": document.write('<body bgcolor="#00AA00" text="#000000">');
    default:          document.write('<body bgcolor="#FFFFFF" text="#000000">');
  }

// The following 3 lines are for display only. They can safely be removed.
  document.write('Browser Type=' + navigator.appName + '<BR>');
  document.write('Browser Version=' + navigator.appVersion + '<BR>');
  document.write('Screen Resolution=' + screen.width + "x" + screen.height);

// End hiding -->
</SCRIPT>

Times Viewed: 3

Leave a Reply

Your email address will not be published. Required fields are marked *