Results 1 to 22 of 22

Thread: Resolution Detection

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Resolution Detection

    Code:
    if (screen.width<1024||screen.height<768) {
      //do something
    }
    This works for IE, what's the equivalent in Netscape 6 and Navigator 4?

    I have tables on my page, but if the resolution is too low, I need to display them on ontop of the other instead of side by side.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    strange... screen.width should work. It was introduced in both Netscape and Internet Explorer 4
    Code:
    window.screen.width
    Does it not work at all?
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    No, it does not. Only in Internet Explorer.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Oh, you may be correct.

    Does 'document.write' work with Netscape? If it doesn't, then that's my problem.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    it does

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Code:
    <script>
    var w = screen.width;
    var h = screen.h;
    
    if (w < 1024 || h < 768) {
        document.write('poo');
    }
    
    </script>
    Nothing shows up in my Netscape 6.2 window when the resolution is 800 x 600. What am I doing wrong? It works fine in IE.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    In Nutscrape, type "javacsript:" in the address bar to see details about script errors...you might be missing something.

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Yeah, it's given me a syntax error, but it doesn't say what line or anything.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    This is weird...
    Code:
    var h = screen.h;
    Shouldn't that be
    Code:
    var h = screen.height;
    ...

  10. #10

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Yeah, I just caught that too. And now I'm getting:

    Error: redeclaration of const kIOServiceProgID
    Source File: chrome://communicator/content/utilityOverlay.js
    Line: 1
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I changed it to:

    Code:
    <script>
    if (screen.width < 1024 || screen.height < 768) {
        document.write("poo");
    }
    </script>
    And it got rid of the errors, but it doesn't display "poo"
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    I take it you are loading this script upon loading the page?

    try...
    Code:
    <script>
    if (screen.width < 1024 || screen.height < 768) {
        self.document.write("poo");
    }
    </script>
    Not sure if its in the standard but it might be worth a try
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  13. #13

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Now it'll write poo no matter what the resolution is.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  14. #14

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Code:
    self.document.write("Width: " + screen.width + "<br>");
    self.document.write("Height: " + screen.height);
    In Netscape, will produce "Width: 800" and "Height: 600" when the resolution is set at 1024 x 768??

    However in Internet Explorer, it will show the right dimensions.

    (Testing in Netscape Navigator 4 and Netscape 6.2, btw)
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    Thats really weird...

    have you tried 'window.screen.width'?
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  16. #16
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Mozilla RC1 - screen.height and screen.width seem to work correctly. Opera 6 as well.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  17. #17

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Can anyone else test this code for me to make sure I'm not crazy?

    Create file with this javascript in it:

    Code:
    self.document.write("Width: " + screen.width + "<br>");
    self.document.write("Height: " + screen.height);
    And with your resolution at 1024x768, see what it says. I tested with Netscape 6.2 and it gave me 800x600.

    I think I tried window.screen, but I'll give it a shot again.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  18. #18

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by The Hobo

    I think I tried window.screen, but I'll give it a shot again.
    Bah, I'll have to give it a shot later. I'm at school and they only have IE.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  19. #19
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I think you might be crazy.

    Anyway, I'm testing by typing "javascript:alert(screen.height);" in the address bar, and I forgot I have Netscape 6.1 installed, but it also gives my correct 1280x1024 screen resolution.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  20. #20

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by JoshT
    I think you might be crazy.

    Anyway, I'm testing by typing "javascript:alert(screen.height);" in the address bar, and I forgot I have Netscape 6.1 installed, but it also gives my correct 1280x1024 screen resolution.
    ***? Yeah, I think I am crazy...

    I did the "javascript:alert(screen.height);" thing you did and it gave the correct dimensions. Let me run the code again one more time...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  21. #21

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Sigh, f'in, sigh.

    I figured it out...

    My original code:

    Code:
    if (screen.width < 1024 || screen.height < 768) {
        self.document.write("poo");
    }
    The Code I should have had:

    Code:
    if (screen.width =< 1024 || screen.height =< 768) {
        self.document.write("poo");
    }
    Now that I wasted everyone's bloody time, thanks for all the help!
    My evil laugh has a squeak in it.

    kristopherwilson.com

  22. #22

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Another thing that was messing it up: I was changing the resolution, then hitting refresh in Netscape. The variables don't reset though, so it was still saying '1024x768' when it was 800x600. So I had to close the browser then reopen it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width