Results 1 to 13 of 13
  1. #1
    Join Date
    Jan 2002
    Posts
    428

    PHP: Display depending on resolution

    I run a skyscrape ad for AdSense on my site. The problem is, anyone with less than 1024x768 resolution has the problem where instead of displaying on the right side, ads are stuck at the bottom due to a lack or horizontal space.

    I figure that the best way to get around this is is to have some PHP? that does something to the effect of grabbing the visitor's resolution and displaying the ad on the side if >=1024x768 and displaying a horizontal ad at the top only if resolution is less than that. Ideas?

  2. #2
    Join Date
    Dec 2002
    Location
    NY, NY
    Posts
    3,975
    you can grab the resolution using javascript

  3. #3
    Join Date
    Jan 2002
    Posts
    428
    Originally posted by ilyash
    you can grab the resolution using javascript

    Assuming I have no programming skills, how would I do that?

  4. #4
    Join Date
    Nov 2003
    Location
    Ljubljana, Slovenija, Europe
    Posts
    298
    <script>

    var windowHeight=window.height;
    var windowWidth=window.width;

    var windowLocationNew='somePageYouCall.php?height='+windowHeight+'&width='+windowWidth;

    window.location=windowLocationNew;

    </script>

    or you could always try paying someone to do it for you

    Airnine

  5. #5
    Join Date
    Jan 2002
    Posts
    428
    Originally posted by airnine
    <script>
    var windowHeight=window.height;
    var windowWidth=window.width;
    var windowLocationNew='somePageYouCall.php?height='+windowHeight+'&width='+windowWidth;
    window.location=windowLocationNew;
    </script>
    or you could always try paying someone to do it for you
    Airnine
    First, I would hire someone if I could afford it. As it is, there are never enough coders for the site to do the needed work.

    That script looks like it opens a new window or something like that?

    What I am looking for is something like

    If resolution < 1024x768 then display xxx
    If resolution >= 1024x768 then display <blank>

  6. #6
    Join Date
    Nov 2003
    Location
    Ljubljana, Slovenija, Europe
    Posts
    298
    on from the code above...

    just put:

    if(windowHeight>768){window.location=somepage.php;}
    else{window.location=somepageelse.php;}

  7. #7
    Join Date
    Jan 2002
    Posts
    428
    Just an update for anyone in the future, here is the working code I used:

    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript">
    var theAd = "larger res";

    if((screen.width >= 1024) && (screen.height >= 768))
    {
    document.write(theAd);
    }
    </script>


    <script type="text/javascript">
    var theAd = "lesserres";

    if((screen.width < 1024) && (screen.height < 768))
    {
    document.write(theAd);
    }
    </script>

    </body>
    </html>

  8. #8
    Join Date
    Jun 2001
    Location
    Partizansk, Russia
    Posts
    74
    What if JavaScript disablet on client side?
    Is there any way to get client's screen resolution in that case?
    Regards,
    SAV

  9. #9
    Join Date
    Jan 2002
    Posts
    428
    Originally posted by sav
    What if JavaScript disablet on client side?
    Is there any way to get client's screen resolution in that case?
    Good question. My theory is as follows:

    It is too much of a pain in the arse to design a site that looks the same across all browsers and configurations. I will make a reasonable effort, but if you don't even have JS installed, don't bother going to my site.

  10. #10
    Join Date
    Nov 2001
    Posts
    551
    Originally posted by sav
    What if JavaScript disablet on client side?
    Is there any way to get client's screen resolution in that case?
    it wouldn't be pretty, but, I think flash can grab the screen resolution (not window size, AFAIK). You could have a quick loading screen that could funnel the visitors to the appropriate url.

    you didn't say it had to be nice did you?

  11. #11
    Join Date
    Nov 2003
    Location
    Ljubljana, Slovenija, Europe
    Posts
    298
    well, no javascript, no fun

    someone has javascript off, but flash is playing,... interesting, possible, but not very likely...

    the fact is, I think I got that somewhere off this forums, 98% of the browser users never alter their settings except email settings, meaning they use the preset stuff, so javascript is on; even, if that is overstated, I think it is, 75% percent is a more likely number, it's still a lot... additionally chances are that, whoever switched the javascript off knows who to switch it on, too, so there's truly no real problem here...

    to pcgamez; why check the height of the screen? wouldn't only the width be adequate?

    regards,
    Airnine

  12. #12
    Join Date
    Nov 2001
    Posts
    551
    Originally posted by airnine
    well, no javascript, no fun

    someone has javascript off, but flash is playing,... interesting, possible, but not very likely...
    agreed, I was just being goofy

    but I looked it up and the actionscript is:
    System.capabilities.screenResolution.x
    System.capabilities.screenResolution.y

    just FYI

  13. #13

    Error in Macromedia docs for System.capabilities...

    I tried using System.capabilities.screenResolution.x, but it didn't work. I did a search on the web and found a page on Macromedia's site saying that their docs were wrong -- here's what I copied directly from their site:

    System.capabilities.screenResolutionX

    This entry should read: System.capabilities.screenResolutionX .(There should be no period following Resolution .)


    System.capabilities.screenResolutionY

    This entry should read: System.capabilities.screenResolutionY .(There should be no period following Resolution .)

    If you'd like to see the full list of revisions in the docs, go to (Macromedia's main site -- www_dot_macromedia_dot_com)/support/flash/documentation/flash_mx_errata/flash_mx_errata03.html

Posting Permissions

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