Solved

fixed background image in Mozilla?

Posted on 2004-08-12
4
163 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
  • 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now