Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Set background due to screen resolution

Reply
Thread Tools

Set background due to screen resolution

 
 
hippo
Guest
Posts: n/a
 
      03-02-2005
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.j pg)';
}
//-->
</SCRIPT>
</head>
<body>
blablabla
</body>
</html>
 
Reply With Quote
 
 
 
 
Fred Oz
Guest
Posts: n/a
 
      03-02-2005
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
 
Reply With Quote
 
 
 
 
hippo
Guest
Posts: n/a
 
      03-02-2005
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.j pg)';
}
</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?

 
Reply With Quote
 
Fred Oz
Guest
Posts: n/a
 
      03-03-2005
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.j pg)';
> }
> </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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can't print white background due to this code.. RAYMOND PISTEY HTML 5 05-02-2010 02:03 AM
How to due with "warning LNK4075: ignoring '/INCREMENTAL' due to Fresh C++ 2 04-22-2008 09:03 PM
Resizing background using CSS and Javascript according to screen resolution Seige Javascript 12 06-23-2006 04:20 AM
Screen placement based on screen resolution Pat Python 5 04-08-2006 03:10 PM
Set screen resolution in batch file by multires David Wood Computer Support 1 02-22-2005 08:54 PM



Advertisments