El.style.backgroundColor= "blue";

renkli.htm

<!DOCTYPE html>
<html>
<body>

<p id="demo">Bu sayfayı tekrar açınca paragrafın arka renk mavi olacak, butona tıklamaya gerek kalmadan.</p>

<script type="text/javascript">

function boya(){
var el= document.getElementById('demo');
el.style.backgroundColor= "blue"; 
}

</script>
<input type="button" value="Set background color" onclick="boya()">
</body>
</html>

I open “renkli.htm”.
I click button. Background color of < p > element is blue.
I close “renkli.htm”.
I open “renkli.htm” again. I don’t click the button. I want to see the background color of < p > element is blue.
How can I do?

you need to save the colour choice. classically through a cookie, more modern by using Web Storage or completely independent by using a server-side programming language.

something like this?

<!DOCTYPE html>
<html>
<body>

<p id="demo">Bu sayfayı tekrar açınca paragrafın arka renk mavi olacak, butona tıklamaya gerek kalmadan.</p>
<script type="text/javascript">
var el;
function boya(){
el= document.getElementById('demo');
el.style.backgroundColor= "blue"; 
el.renk= el.style.backgroundColor;

// Check browser support
if (typeof(Storage) !== "undefined") {
    // Store
    localStorage.setItem("arkarenk", el.renk);

    
} else {
    document.getElementById("demo").innerHTML = "Sorry, your browser does not support Web Storage...";
}
}

// Check browser support
if (typeof(Storage) !== "undefined") {

    // Retrieve
   var el2 =  document.getElementById("demo");
el2.style.backgroundColor= localStorage.getItem("arkarenk");
} else {
    document.getElementById("demo").innerHTML = "Sorry, your browser does not support Web Storage...";
}


</script>
<input type="button" value="Set background color" onclick="boya()">
<br>

 http://www.w3schools.com/html/html5_webstorage.asp
<br> http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_webstorage_local



</body>
</html>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.