Forum Moderators: open
<!DOCTYPE HTML>
<title>Test</title>
<embed id="foo" src="http://www.w3schools.com/media/bookmark.swf" width="400" height="40" type="application/x-shockwave-flash" />
<script type="text/javascript">
document.getElementById("foo").setAttribute("bgcolor", "#00FF00");
</script>
document.getElementById("foo").style.backgroundColor='#0f0';
<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
<script type="text/javascript">
var x;
var y;
var z;
z = "#00FF00";
if (z == "transparent" || z == "") {
x = ""; y = "transparent";
}
else {
x = z; y = "window";
}
</script>
</head>
<body>
<embed id="foo" bgcolor="'+x+'" wmode="'+y+'" src="http://www.w3schools.com/media/bookmark.swf" width="400" height="40" type="application/x-shockwave-flash" />
</body>
</html> To see what I mean please try adding bgcolor="#00FF00" to the embed code and compare it with changing the style background color.
<embed id="foo" wmode="transparent" src="http://www.w3schools.com/media/bookmark.swf"
width="400" height="40" type="application/x-shockwave-flash"></embed>
<script>
document.getElementById("foo").style.backgroundColor = '#0f0';
</script>
Indeed, the bgcolor (even the default) appears to be overwriting the style.backgroundColor - which still seems to be present, but is behind the embed bgcolor?
Setting bgcolor="transparent" in the HTML shows the style.backgroundColor, but a darker shade - I suspect 'transparent' is not completely transparent, or may be that wmode attribute is required as well?!
<!DOCTYPE HTML>
<title>Test</title>
<embed bgcolor="transparent" src="http://www.w3schools.com/media/bookmark.swf" width="400" height="40" type="application/x-shockwave-flash" /> However, looking at your code, if you also set wmode="transparent" then this appears to work OK (you don't need to set bgcolor at all) - You can then set the backgroundColor in the CSS
The code you have above doesn't work because where you are trying to output x and y you are not in a script section!
bgcolor ... Use this attribute to override the background color setting specified in the Flash file.
The bgcolor value shouldn't be set to transparent -- just a hexadecimal RGB value. That's why browsers don't interpret it correctly...
What if a user decides to display the flash default background color?
<embed id="foo" bgcolor="'+x+'" wmode="'+y+'"
src="http://www.w3schools.com/media/bookmark.swf" width="400" height="40"
type="application/x-shockwave-flash" />
<script type="text/javascript">
var htm = '';
htm += '<embed id="foo" bgcolor="' + x + '" wmode="' + y + '"';
htm += ' src="http://www.w3schools.com/media/bookmark.swf" width="400" height="40"';
htm += ' type="application/x-shockwave-flash" />';
document.write(htm);
</script>
It appears that Flash (rather than the browser) attempts to convert anything in the bgcolor attribute to an RGB colour?!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" href="http://sites.google.com/site/mori79b/icons-logos/favicon.ico" type="image/x-icon">
</head>
<body bgcolor="#transp">
</body>
</html> This assumes x and y have been defined above in your code.
It appears that Flash (rather than the browser) attempts to convert anything in the bgcolor attribute to an RGB colour?!
It doesn't seem to be correct. Please try the following valid code...
...is there an alternative to the JavaScript setAttribute method?
document.getElementById("foo").bgcolor = "#00FF00";