The following code
$(document).ready(function(){
sessionStorage.test = false;
alert( sessionStorage.test );
if ( sessionStorage.test ) {
alert("I dont care about your conditions!");
}
});
produces the following popups:
false
I dont care about your conditions!
even though sessionStorage.test
is clearly set to false. Why is that the case? According to this answer https://stackoverflow.com/a/17986241/2311074, this should work. What am I doing wrong? I am using XAMPP - does it maybe have problems with sessionStorage? Here is the complete code of my test file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script >
$(document).ready(function(){
sessionStorage.test = false;
if ( sessionStorage.test ) {
alert("I dont care about your conditions!");
}
});
</script>
</head>
<body>
<!-- page content -->
</body>
</html>
The default getter/setter for sessionsStorage are:
sessionStorage.setItem('keyName', 'value');
sessionStorage.getItem('keyName')
So, for example:
sessionStorage.setItem('test',false);
if (sessionStorage.getItem('test') != "false") {
..........
}
Duplicate Topics:
- sessionStorage setItem returns true or false
- sessionStorage isn't working as expected
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With