www.webdeveloper.com
Results 1 to 2 of 2

Thread: Displaying Backgrounds base on screen resolution

  1. #1
    Join Date
    Jul 2012
    Posts
    2

    Displaying Backgrounds base on screen resolution

    Hi,

    I am using javascript to check the screen resolution and if a certain condition is met i want it to pull a particular css file. however it doesnt seem to be working, i am completely new to javascript an idiot really please if help.

    Code:
    <script type="text/javascript">
    <!--
    
    var width = screen.width; 
    var height = screen.height;
    
    if ((width==800) && (height==600)){document.write('<link rel="stylesheet" type="text/css" href="/includes/800x600.css" />'); } 
    if ((width=1024) && (height==768)){document.write('<link rel="stylesheet" type="text/css" href="../includes/1024x768.css" />'); } 
    if ((width==1920) && (height==1080)){document.write('<link rel="stylesheet" type="text/css" href="../includes/1920x1080.css" />'); } 
    if ((width==1280) && (height==768)){document.write('<link rel="stylesheet" type="text/css" href="../includes/1280x768.css" />'); } 
    if ((width==1440) && (height==900)){document.write('<link rel="stylesheet" type="text/css" href="../includes/1440x900.css" />'); } 
    --></script>

  2. #2
    Join Date
    Jun 2012
    Location
    Dark Side of the Moon
    Posts
    70
    Here is a link on what you are trying to do. I don't see anything wrong, except maybe the second if has a typo, so if your running 1024 it may fail, should have the == and not just =. Otherwise, let us know what 'its not working' means, maybe an error, or what you see happen.

    http://www.pageresource.com/jscript/jscreen.htm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles