SessionStorage different pages Javascript

111 views Asked by At

I am trying to set my background color on the firstpage, and then trying to get the sessionstorage background for the second page. This is what I got:

First Page:

function NatureBackground()
{
    $('body').css('background-image', 'url("images/background-nature.jpg")');
    sessionStorage.setItem('background', 'images/background-nature.jpg')
}

Second Page:

$(document).ready(function()
{
    if(sessionStorage.getItem('background') === null)
    {
        $('body').css('background-image', 'url("images/background-wood.jpg")');
    }
    else
    {
        $('body').css('background-image', 'url(' + sessionStorage.getItem('background') + ')');
    }
});

On the first page the background remembers the photo, but the secondpage keeps getting the background-wood.jpg. What am I doing wrong?

0

There are 0 answers