473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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="JavaScript">
<!--
if (screen.width == 1024) {
document.body.style.backgroundImage='url(myimage.j pg)';
}
//-->
</SCRIPT>
</head>
<body>
blablabla
</body>
</html>
Jul 23 '05 #1
3 3070
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
Jul 23 '05 #2
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?

Jul 23 '05 #3
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
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Markus Mohr | last post by:
Hi, everyone, I have a special problem: For every monitor resolution in 200 pixel steps from 800 to 1600 pixels I have an image to be shown as centered background-image. Those images all...
1
by: Bru, Pierre | last post by:
hi, I designed a background for a page. it is for 1024*768 screens. but everyday, the screen go larger and I dont want everyone to wait for a backgroud larger than needed. so I used a tiled...
5
by: seajays | last post by:
OK, I've managed to get just about everything working in CSS and XHTML, but there is one last peice of the jigsaw. http://www.seajays.org.uk/2know_dev/ At the moment on the site, I have a gray...
6
by: John Ortt | last post by:
Hi there everyone, I have a part info form which has a faded image of our company logo as a background. I want to replace the faded image with a bright red warning image on items which have run...
5
by: Maxi | last post by:
I have a 30X16 cells table in my html page. Table height and width are set to 100%. I have set size of every cell inside the table to 24 pixel. When I open the html page in maximize state in...
14
by: Seige | last post by:
Ever had headache when you can't resize the background width using CSS: body{ background: url(/images/bg.jpg) ; background-width: 800px; } It won't work, would it? Of course not, it's not even...
9
by: Steve Wright | last post by:
Hi I'm developing a webpage that needs to include a different stylesheet depending on the screen resolution. I know that I could read the resolution in javascript and then do some sort of...
1
by: nasima khan | last post by:
Hi, i am nasima. I have got a code for setting the screen resolution of my page, but i am unable to understand. Can any one give a complete data explanation of the below code. Sub ChangeRes(X...
10
by: =?Utf-8?B?UmljaA==?= | last post by:
A lot of users at my workplace use different screen resolutions, and I build apps to use 1680 x 1050 pixels res by default. But some users are using 800 x 600, and the apps are too large for their...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.