0

when i change my background color i save name color to localstrog when i reload page must $value get name color from javascript and display in css style see my code for understanding my question

<html>
<head>
<script>
    function chc(gv){
        if(gv=="red"){
            document.getElementById("main").style.backgroundColor="red";
            localStorage['mysave']="red"; 
        }
        else if(gv=="green"){
            document.getElementById("main").style.backgroundColor="green";
            localStorage['mysave']="green"; 
        }
     }
</script>

<!--now php get data from localstrog by javascript-->
<?php  $value = "<script type='text/javascript'>document.write(localStorage.mysave);</script>"; ?>

<style>
    #main{
        width: 200px;
        height: 100px;
        background-color:<?php echo $value; ?>;
    }
</style>

</head>
<body>
    <button onclick="chc('red')">red</button> <button     onclick="chc('green')">green</button>
    <div id="main">
        testing
    </div>
    <h3>reload page the php dont get data from localstrog and no display ni style</h3>
</body>
</html>
Cameron Hurd
  • 4,836
  • 1
  • 22
  • 31
mody
  • 65
  • 2
  • 7

0 Answers0