SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Scott Botkins's Avatar
    Join Date
    Jun 2003
    Location
    cincinnati
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    show ad based on screen resolution?

    Hey guys, I was wondering if you had any idea how to show a ad based on screen resolution. Sort of like how espn.com has it...when your on 800 by 600 it doesn't show the ad and msn table on the right but when you are on 1024 or higher it does. Does anyone have any idea how to do this?

    Thanks,
    Cincinnati Web Design - Creative Web Design by Scott Botkins

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This topic comes up occasionally, but I've always thought it was odd to make layout decisions based on monitor resolution because that assumes the user has (or will) maximize the browser window. Oh well. The following may not be what you want... I don't know what you want to do in each case because there are many different ways you might implement this. So here's something very simple.
    Code:
    <html>
    <head>
    <script>
    
    window.onload = setBanner;
    
    function setBanner()
    {
      var w = screen.availWidth;
      var i = document.getElementById('banner');
      if (w >= 1000) {
        i.src = 'banner_big.jpg'
      }
      else if (w >= 700) {
        i.src = 'banner_medium.jpg'
      }
      else {
        i.src = 'banner_small.jpg'
      }
    }
    </script>
    </head>
    <body>
    
    <img id='banner' src=''>
    
    </body>
    </html>


Bookmarks

Posting Permissions

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