Domanda

I have a simple application written in Visual Studio 2010.

The java script behind a button click:

function btnClicked() {
    alert(localStorage["name"]);
    localStorage["name"] = "Bill";
}

When I click it the first time, I get "undefined" and the second time I get "Bill", which is correct.

But if I restart the application, I'd hope it would display "Bill" the first time I click the button.

It doesn't. What am I missing?

È stato utile?

Soluzione

But when I restart the application...

... you restart it. Which includes wiping any localStorage contents. Try running your page in a browser and it should work just fine.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top