Search code examples
javascriptsession-storage

sessionStorage, Variable script breaks


So, I have pages - A and B. On the page A has a button, when we click on the button opens a page B and opens a hidden block.

I'm certainly doing something wrong, but what?

this template A

<script>
$('button').click(function () {

var openHiddenBlock = document.setItem('true');
    sessionStorage.setItem('openHiddenBlock', 'true');

    location.href = "http://B.com";

});
</script>

this template B

<script>
$(document).ready(function(){

    if(sessionStorage.getItem('true') == 'true') {
        $('HiddenBlock').slideToggle(); // opening animation 
    }
});
</script>

Solution

  • On page B you're testing for an item with the key of "true" but on page A you're setting an item with key "openHiddenBlock".