Set background due to screen resolution

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hippo

    #1

    Set background due to screen resolution

    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="JavaS cript">
    <!--
    if (screen.width == 1024) {
    document.body.s tyle.background Image='url(myim age.jpg)';
    }
    //-->
    </SCRIPT>
    </head>
    <body>
    blablabla
    </body>
    </html>
  • Fred Oz

    #2
    Re: Set background due to screen resolution

    hippo wrote:
    [...][color=blue]
    > 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.[/color]

    In which browser on what platform? It works in Safari, IE,
    Firefox and Netscape on Mac (but not Opera 6).
    [color=blue]
    >
    > Got anyone a clue?[/color]

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

    if ( self.screen.wid th == 1024) {


    Some issues totally unrealted to your problem:

    [...][color=blue]
    > <SCRIPT language="JavaS cript">[/color]

    <script type="text/javascript">

    The language attribute is depreciated, type is required.
    [color=blue]
    > <!--[/color]

    Don't bother hiding scripts.



    --
    Fred

    Comment

    • hippo

      #3
      Re: Set background due to screen resolution

      I do this on a winxp, ie6.0

      I changed my code to:

      <script type="text/javascript">
      if ( self.screen.wid th == 1024) {
      document.body.s tyle.background Image='url(terr ein.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?

      Comment

      • Fred Oz

        #4
        Re: Set background due to screen resolution

        hippo wrote:[color=blue]
        > I do this on a winxp, ie6.0
        >
        > I changed my code to:
        >
        > <script type="text/javascript">
        > if ( self.screen.wid th == 1024) {
        > document.body.s tyle.background Image='url(terr ein.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?[/color]

        OK. Finally got access to an XP box:

        if (screen.width == 1280) {
        document.body.s tyle.background Image='url(1.gi f)';
        }

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

        --
        Fred

        Comment

        Working...