javascript function to set body background from custom value
-
Hi,
I’m trying to use an image name as a post custom value (e.g img1.jpg) for a page and want to pass it as an array variable to a JavaScript function, to replace the background image set in the stylesheet but it doesn’t seem to be working.Here’s my code (in the header.php):
<script type="text/javascript"> function changeBackground(whichImage) { if(document.body){ document.body.style.backgroundImage = "url(whichImage)"; } </script> </head> <?php $values = get_post_custom_values("bgimage") ?> <body onLoad="changeBackground($values[0])"> </body> </html>It could be something really obvious but I’m missing it.
Help!!
The topic ‘javascript function to set body background from custom value’ is closed to new replies.