Set background due to screen resolution

Discussion in 'Javascript' started by hippo, Mar 2, 2005.

  1. hippo

    hippo Guest

    Hi,

    What i would like to have is the following:
    User comes on page and script detects what resolution user have.
    Due to screen resolution the background image of the page is changed.

    I try the follwing but i an errors all the time (error: object
    required). This is strange, without the if statement and implement the
    code in a function the code works.

    Got anyone a clue?

    <html>
    <head>
    <title>mysample</title>
    <SCRIPT language="JavaScript">
    <!--
    if (screen.width == 1024) {
    document.body.style.backgroundImage='url(myimage.jpg)';
    }
    //-->
    </SCRIPT>
    </head>
    <body>
    blablabla
    </body>
    </html>
    hippo, Mar 2, 2005
    #1
    1. Advertising

  2. hippo

    Fred Oz Guest

    hippo wrote:
    [...]
    > I try the follwing but i an errors all the time (error: object
    > required). This is strange, without the if statement and implement the
    > code in a function the code works.


    In which browser on what platform? It works in Safari, IE,
    Firefox and Netscape on Mac (but not Opera 6).

    >
    > Got anyone a clue?


    The if statement is likely the issue - have you seen what
    screen.width actually returns? Have you tried:

    if ( self.screen.width == 1024) {


    Some issues totally unrealted to your problem:

    [...]
    > <SCRIPT language="JavaScript">


    <script type="text/javascript">

    The language attribute is depreciated, type is required.

    > <!--


    Don't bother hiding scripts.



    --
    Fred
    Fred Oz, Mar 2, 2005
    #2
    1. Advertising

  3. hippo

    hippo Guest

    I do this on a winxp, ie6.0

    I changed my code to:

    <script type="text/javascript">
    if ( self.screen.width == 1024) {
    document.body.style.backgroundImage='url(terrein.jpg)';
    }
    </script>

    and still the error: object required.
    my screen is 1024. if i do any other value, no error occurs, but also
    nothing happens.

    any other clues?
    hippo, Mar 2, 2005
    #3
  4. hippo

    Fred Oz Guest

    hippo wrote:
    > I do this on a winxp, ie6.0
    >
    > I changed my code to:
    >
    > <script type="text/javascript">
    > if ( self.screen.width == 1024) {
    > document.body.style.backgroundImage='url(terrein.jpg)';
    > }
    > </script>
    >
    > and still the error: object required.
    > my screen is 1024. if i do any other value, no error occurs, but also
    > nothing happens.
    >
    > any other clues?


    OK. Finally got access to an XP box:

    if (screen.width == 1280) {
    document.body.style.backgroundImage='url(1.gif)';
    }

    works like a charm in every browser tested, including
    IE 6.0.2800 on Windows XP SP1.

    --
    Fred
    Fred Oz, Mar 3, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew FPGA
    Replies:
    0
    Views:
    960
    Andrew FPGA
    Sep 26, 2005
  2. Pat
    Replies:
    5
    Views:
    532
  3. Fresh
    Replies:
    2
    Views:
    622
    Bo Persson
    Apr 22, 2008
  4. RAYMOND PISTEY
    Replies:
    5
    Views:
    530
    RAYMOND PISTEY
    May 2, 2010
  5. Seige
    Replies:
    12
    Views:
    395
    Matt Kruse
    Jun 23, 2006
Loading...

Share This Page