Solved

fixed background image in Mozilla?

Posted on 2004-08-12
4
167 Views
Last Modified: 2010-04-06
Hi, I am trying to show a background jpeg that stays in a fixed position even when the window is scrolled. My code works fine in IE6 but only half-works in Mozilla/Firefox. In Moz it either does not appear at all or it appears and sets the background of the rest of the page white. Seems to be the no-repeat option that Moz does not like, but I must have that feature, I only want 1 copy of the picture.

I have also tried using HTML/css in the header section but get exactly the same results!
Please help, this is driving me nuts!

code in body section:

<script language="JavaScript1.2">
    if (document.all||document.getElementById) {
        document.body.style.background="url('nirvana.png') black left no-repeat fixed";
    }
</script>

0
Comment
Question by:azriel_99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Belthazor earned 500 total points
ID: 11790865
Hi,
This code ....
-------------------------------------------------------------------------------
<html>

<head>
<script type="text/javascript">
function ChangeColor()
{
    if (document.all||document.getElementById) {
      document.body.style.background="url('nirvana.png') black left no-repeat fixed";
     }
}
</script>
</head>

<body onLoad="ChangeColor()">
Content
</body>

</html>
---------------------------------------------------------------------------------------

.. works in both IE and Firefox

Belthazor
0
 

Author Comment

by:azriel_99
ID: 11792184
thou art a gentleman and a scholar, and a shagmeister
thanks Belthazor! for extra karma could you tell me the technical reason why that works as opposed to my code?
cheers!
0
 
LVL 3

Expert Comment

by:Belthazor
ID: 11792687
hi azriel_99,
i think this is because you can not access the 'document.body'-object before initializing it (it gets initialized where the <body> tag is), because when you take the whole <script>....</script> tag into your body, its gonna work too, but if i were you, i would keep the function.
I like to use functions because you can call them whereever you want and as many times you want, and you can write all of them into the <head> tag, so all of your script is in a single <script> tag!

Belthazor
0
 

Author Comment

by:azriel_99
ID: 11794008
ahh I guess that makes sense. I am new to this web programming stuff - it certainly is quirky! thanks a lot, may jewels and sweet meats rain upon you!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question