Jump to content

storageobject in webStorage


Matej

Recommended Posts

Hi , how can i storage object in sessionStorage?

 

function setIt(){var kek=document.getElementById("kek"); //text inputwindow[kek.value]={};window[kek.value].name = "name";sessionStorage.setItem(kek.value ,window[kek.value])}function getIt(){alert(sessionStorage.getItem(kek.value.name))} /this allerts null

i also tried to parse it

 

var one=sessionStorage.getItem(kek.value);var two=JSON.parse(one);alert(two.name)

it also didnt work

Link to comment
Share on other sites

i think it was somewhere on codeacademy ,not sure if in their tutorials or on forum as response, what is so bad on it?

(well yea in this case it have input.value as name but whats bad on it overall?)

Edited by Matej
Link to comment
Share on other sites

i don't understand what do you mean.

 

var input=document.getElementById("input"); // text input

and i set

window[input.value]="hello world" => if input values is "one" than its window["one"] which is the same thing as var one="hello world"

Edited by Matej
Link to comment
Share on other sites

You take a text input and create a GLOBAL with the name of the text input and you don't see anything wrong with that?

 

You are not assigning a text input to a global. You are creating a global that has the name of the text input?

Link to comment
Share on other sites

You take a text input and create a GLOBAL with the name of the text input and you don't see anything wrong with that?

 

You'll have to explain it. Nothing is obvious, it only seems that way to an experienced person.

I only see one thing wrong with it: It gives the user the ability to make the program break by overwriting important variables.

 

A simple solution is to only give the user access to a particular object.

// At the beginning of the programvar globals = {};// Elsewhere in the programvar input=document.getElementById("input");globals[input.value] = "hello world";
Link to comment
Share on other sites

You take a text input and create a GLOBAL with the name of the text input and you don't see anything wrong with that?

 

 

I'm aware of this problem, i mentioned it

and yea ingolme your way is better :)

 

Thanks for answers

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...