WordPress.org

Ready to get started?Download WordPress

Forums

javascript function to set body background from custom value (1 post)

  1. pressnewb1
    Member
    Posted 5 years ago #

    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!!

Topic Closed

This topic has been closed to new replies.

About this Topic