SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript and Php detect resolution

    Hey, I'm build a site that I want to look nice in all resolutions..

    I made all the table widths and things like that relative as much as possible (100% width) and they all expand fine and look good in 800x600 and higher resolutions (I'm really not concerned with 640x480)

    But, theres one part of the page that has "un grande problema"..

    Simply put, theres a large image that doesnt fit in lower resolutions, so I want to detect what resolution the user is using and then replace the image accordingly.

    So, basically, I want to have two versions of this image, one "small" (for 800x600 and anything lower) and the other "large" (for anything larger than 800x600), and I want to display the appropriate image, but still have the same website, you know? I could grab a javascript that redirects according to screen size, but then I have to maintain two different sites..

    I know I cant detect the resolution with php, so is there some way I can detect it with javascript, then pass it to php? I would be willing to do it all in javascript... but I want it to work on as many browsers as possible and I am more familiar with php than javascript..

    So whats the best way to replace the image according to resolution..?

    Thanks!
    Marc Gugliuzza
    marc.gugliuzza.com



  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should give you a start Marc:

    <SCRIPT language="javascript">

    var sw = screen.width;
    var sh = screen.height;

    var html ="<a href=\"script.php?sw="+sw+"&sh="+sh+"\">Click here</a>";
    document.write(html);

    </SCRIPT>

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, thanks a bunch. I don't want them to click though... want it to be as quick and unnoticeable as possible.. so I'll want it to forward the user to the php page with the variables.. I think this modification should work:

    <SCRIPT language="javascript">

    var sw = screen.width;
    var sh = screen.height;

    window.location="script.php?sw="+sw+"&sh="+sh+""

    </SCRIPT>

    as you can probably tell im quite new to javascript.. I think this will work, though..

    Thanks again, Sean!
    Marc Gugliuzza
    marc.gugliuzza.com




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
  •