Solved

fixed background image in Mozilla?

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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 …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

734 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