mike99c
asked on
Cannot add a style to a body tag using JavaScript if FireFox detected
Hello,
I have a website which has a background tile image. However, I need to change the background tile image if the browser is Firefox.
Hence for IE the body tag is:
<body>
But for Firefox it must be:
<body style='background-image:ur l(/images/ common/mai n_bg.gif)' >
I have attached a code snippet in which I successfully use JavaScript to detect if the browser is Firefox. However, when I view the site in Firefox the whole page simply displays:
style='background-image:ur l(/images/ common/mai n_bg.gif)'
and that's it, just that line of code and nothing else. It works fine in IE.
I have a website which has a background tile image. However, I need to change the background tile image if the browser is Firefox.
Hence for IE the body tag is:
<body>
But for Firefox it must be:
<body style='background-image:ur
I have attached a code snippet in which I successfully use JavaScript to detect if the browser is Firefox. However, when I view the site in Firefox the whole page simply displays:
style='background-image:ur
and that's it, just that line of code and nothing else. It works fine in IE.
<script type="text/javascript">
function checkfirefox(){
if (navigator.userAgent.indexOf("Firefox")!=-1)
document.write("style='background-image:url(/images/common/main_bg.gif)'")
}
</script>
<body onload="checkfirefox()">
also,
looking at the script code you're writing:
try:
document.body.style.backgr ound =
finally what errors are you getting...is the path correct?
looking at the script code you're writing:
try:
document.body.style.backgr
finally what errors are you getting...is the path correct?
ASKER
In response to the 3 preceding reponses:
1. I have checked the styles by manually embedding them and ite work. So I have ruled out any issue with the style.
2. I have looked at the quirksmode link but I have no issue detecting the browser, it is simply embedding the css that is the problem.
3. I have checked the path by embedding the style so that is not the issue either.
1. I have checked the styles by manually embedding them and ite work. So I have ruled out any issue with the style.
2. I have looked at the quirksmode link but I have no issue detecting the browser, it is simply embedding the css that is the problem.
3. I have checked the path by embedding the style so that is not the issue either.
you're embedding style, but for what element? what i mean is where is that code going to be placed? that's why I said explicitedly set
2:
3:
4:
5:
6:
7:
<script type="text/javascript">
function checkfirefox(){
if (navigator.userAgent.index Of("Firefo x")!=-1)
{
document.body.style.backgr ound = url(/images/common/main_bg .gif);
}
}
</script>
<body onload="checkfirefox()">
2:
3:
4:
5:
6:
7:
<script type="text/javascript">
function checkfirefox(){
if (navigator.userAgent.index
{
document.body.style.backgr
}
}
</script>
<body onload="checkfirefox()">
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if not, then there may be an error with your styles.