Okay so I have two pages, 1 page contains a table with clickable div's, plenty of them, and when 1 is pressed it leads to page 2 which contains a form in which user enters information that is stored in local storage, now what I'm trying to achieve is to change the color of that DIV on page 1 that if the form was successfully submitted, and I mean change it permanently.
This is the code I have used on page 1:
window.onload = function () {
myCustomColor = 'red';
localStorage.setItem('myDataStorage', myCustomColor);
var d = document.getElementsByClassName("circleBase type1");
for(var i = 0; i < d.length; i++) {
d[i].onclick = function() {
window.open("EnterInformation.html");
}
}
}
with this code i store the color to the local storage. Now for testing purposes I added an ID to just one div id='L1'
, so I tried getting the item by .getItem
like this:
function changeColor() {
var myLoadedColor = localStorage.getItem('myDataStorage');
document.getElementById('L1').style.backgroundColor = myLoadedColor;
<input type="submit" name="appointment" value="" class="btn-warning" onclick="SaveInfo(); closeSelf(); changeColor()" />
Nothing happens?!
Now I wanted to see if it is even getting the stored color by trying to change the color of div on page 2(EnterInformation.html
) and it works but it changes the color of the div for a second and then returns it to default, why is that happening? Any advice?
My original question which I wanted to post was Is it possible to change the color of the clicked div from another page, but this is far more complicated than I imagined!
P.S. both pages are open at the same time on different tabs.