KorryRogers
Posts: 0
Joined: Fri Aug 15, 2014 2:53 am

Set Default Values for Local Storage Variables

I used to be able to do this in the old editor, but I'm having problems in the new one. I'm trying to setup some local storage variable default values when the app launches. Here's the code I've tested and none of it works. I've even tried putting it in a setTimeout() function to no avail.

if(!localStorage.onlineStatus localStorage.onlineStatus === null localStorage.onlineStatus = '') {
localStorage.onlineStatus = '0'
}

What am I doing wrong? How can I setup a default value? TIA

KorryRogers
Posts: 0
Joined: Fri Aug 15, 2014 2:53 am

Set Default Values for Local Storage Variables

Also, I'm running this on the page show event of the launch page.

Ihor Didevych
Posts: 0
Joined: Wed Nov 19, 2014 7:55 pm

Set Default Values for Local Storage Variables

Hi Korry,

Your approach is correct.
Could you clarify, how do you test your LSV ?

KorryRogers
Posts: 0
Joined: Fri Aug 15, 2014 2:53 am

Set Default Values for Local Storage Variables

I'm just looking at the local storage variables directly in the dev tools in Chrome. They don't get created.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Set Default Values for Local Storage Variables

Hi Korry,

Here is a correct code:

precode

var currentValue = localStorage.getItem("onlineStatus");

if(!currentValue currentValue === null currentValue = '') {
//Replace this value with your goal default value.
var defaultValue = "0&quot
localStorage.setItem("onlineStatus", defaultValue);
}

/code/pre

More details here: http://www.w3schools.com/html/html5_w...

Regards

Return to “Issues”