Robert Granlund
asked on
javascript to change background color
Is there a way to temporarily set a html background color to #000000 until the window has fully loaded and then change it to transparent?
http://www.webcodingtech.com/javascript/change-background-color.php
ASKER
User N. That is an interesting example but it does not answer my question. I want to set a page color until the page completely loads that I want the background color to automatically change.
onLoad and onUnload
The onLoad and onUnload events are triggered when the user enters or leaves the page.
The onLoad event is often used to check the visitor's browser type and browser version, and load the proper version of the web page based on the information.
Both the onLoad and onUnload events are also often used to deal with cookies that should be set when a user enters or leaves a page. For example, you could have a popup asking for the user's name upon his first arrival to your page. The name is then stored in a cookie. Next time the visitor arrives at your page, you could have another popup saying something like: "Welcome John Doe!".
The onLoad and onUnload events are triggered when the user enters or leaves the page.
The onLoad event is often used to check the visitor's browser type and browser version, and load the proper version of the web page based on the information.
Both the onLoad and onUnload events are also often used to deal with cookies that should be set when a user enters or leaves a page. For example, you could have a popup asking for the user's name upon his first arrival to your page. The name is then stored in a cookie. Next time the visitor arrives at your page, you could have another popup saying something like: "Welcome John Doe!".
I think the .ready() function in jQuery would be the most efficient way to do what you want. Something like this:
...
<style type="text/css">
.body_0 {background-color:#def}
.body_1 {background-color:#000}
</style>
<script src="scripts/jquery-1.6.1. min.js" type="text/javascript"></s cript>
<script type="text/javascript">
$(document).ready(function () {
$("body").removeClass('bod y_1').addC lass('body _0');
});
</script>
</head>
<body class="body_1">
...
Trying to do it with just javascript looks pretty involved from what I read.
http://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery
...
<style type="text/css">
.body_0 {background-color:#def}
.body_1 {background-color:#000}
</style>
<script src="scripts/jquery-1.6.1.
<script type="text/javascript">
$(document).ready(function
$("body").removeClass('bod
});
</script>
</head>
<body class="body_1">
...
Trying to do it with just javascript looks pretty involved from what I read.
http://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery
ASKER
@TommyBoy and et all:
I need to change it here:
<!DOCTYPE html>
<html style="background-color: #000000;">
So I need to use javascript here to change the color from black to transparent after page fully loads.
I need to change it here:
<!DOCTYPE html>
<html style="background-color: #000000;">
So I need to use javascript here to change the color from black to transparent after page fully loads.
I would suggest a similar solution:
<!DOCTYPE html>
<html class="html_1">
<head>
<title>Untitled</title>
<style type="text/css">
.html_0 {background-color:transpar ent}
.html_1 {background-color:#000}
</style>
<script src="scripts/jquery-1.6.1. min.js" type="text/javascript"></s cript>
<script type="text/javascript">
$(document).ready(function () {
$("html").removeClass('htm l_1').addC lass('html _0');
});
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html class="html_1">
<head>
<title>Untitled</title>
<style type="text/css">
.html_0 {background-color:transpar
.html_1 {background-color:#000}
</style>
<script src="scripts/jquery-1.6.1.
<script type="text/javascript">
$(document).ready(function
$("html").removeClass('htm
});
</script>
</head>
<body>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PS ignore
<script type="text/javascript" src="jscripts/callStats.js "></script >
its irrelevant - thanks to COPY / PASTE
<script type="text/javascript" src="jscripts/callStats.js
its irrelevant - thanks to COPY / PASTE
ASKER
I have used this to rectify the issue with Google Chrome flashing white when you load a new screen. It does not validate however, it works like a charm. Thanks.