Jump to content

HTML5 localStorage Object


Spunky

Recommended Posts

I recently came across an article about an alternative to cookies. The article was in-depth and I always fall-back to w3schools to do a wonderful job at making concepts easy to understand so I came searching for it and found it: http://www.w3schools.com/html/html5_webstorage.asp

 

However, the information here seems to be very limited. For example it doesn't explain how to empty the storage.

 

I always start out with a basic example of my own to establish the basics and make sure I understand it.

 

Well this is what I have, the function is ran when the body loads.

<script>function user_visit() {    if(typeof(Storage) !== "undefined") {        if (localStorage.visit) {            localStorage.visit = true;        } else {            localStorage.visit = false;        }          } else {        document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";    }		if(localStorage.visit = true){		include_first_forum();	}	else{		alert("Welcome first timer!");	}}</script>

When I first ran the script though, it ran the function include_first_forum(); So I don't know how to confirm that this is really working, I didn't get a chance to have it do something different the first time. Can someone direct me to a good source to learn more about this concept?

 

Link to comment
Share on other sites

localStorage works as long as visitor is on the site - you exit the site = localStorage is destroyed=you enter the site again=new local storage is made.

If you want to check if someone has already been on your site , use sessionStorage (it doesnt get destroyed when visitor exit site )

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

Edited by Matej
Link to comment
Share on other sites

localStorage works as long as visitor is on the site - you exit the site = localStorage is destroyed=you enter the site again=new local storage is made.If you want to check if someone has already been on your site , use sessionStorage (it doesnt get destroyed when visitor exit site )https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

 

I think you have localStorage and sessionStorage mixed up. localStorage is "permanent" while sessionStorage is deleted when the browser closes.

Link to comment
Share on other sites

 

I think you have localStorage and sessionStorage mixed up. localStorage is "permanent" while sessionStorage is deleted when the browser closes.

 

Correct.

 

The localStorage Object

The localStorage object stores the data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

The sessionStorage Object

The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the browser window.

Right from the link I posted in my first post.

Link to comment
Share on other sites

So you did not see this bit on link about removing specific local storage item?

localStorage.removeItem("lastname");

 

and foe clearing all

localStorage.clear();

 

So you did not see the part of my post that clearly stated I didn't see how to remove items? Please don't be sarcastic and rude, thanks.

Link to comment
Share on other sites

I was NOT being sarcastic, and definitly not rude, i just pointef out the FACT that information about removing items IS there, IF you bothered to open your fr$ing eyes and look, Which is sacastic and rude.

 

"In that link it does state the localStorage.remove item function. It's located towards (area on page). Hope that helps!" Would have been the proper, friendly way to go about it. After all, I am only human and clearly missed it. I'm sorry you do not see how your posts come across as rude, but to others, not everyone, but some, they can.

Link to comment
Share on other sites

IF you read everything as being sarcastic it probably can be read as that, IT was playfully pointing out the removal of items for localstorage IS there, Unfortunately being written reply and not spoken, you cannot determine the tone at which it was sent, but you have decided from your bitter sarcastic world, that it was! WRONGLY i might add.

Link to comment
Share on other sites

 

So you did not see the part of my post that clearly stated I didn't see how to remove items? Please don't be sarcastic and rude, thanks.

 

I think you might have misinterpreted his first post. I do believe it was an honest question without any bad intentions. The written form of communication is missing a lot of context that verbal and visual communication have.

 

 

I was NOT being sarcastic, and definitly not rude, i just pointef out the FACT that information about removing items IS there, IF you bothered to open your fr$ing eyes and look, Which is sacastic and rude.

 

This isn't the appropriate way to deal with somebody who got offended by one of your posts. Rather than get defensive you should have apologized and cleared up the misunderstanding. Otherwise you're giving the impression that you really are following the attitude he perceived in your previous post.

Link to comment
Share on other sites

Why should I apologise? SHE (apology required here foxy) is the one who misinterperated my post, I corrected on what would be really sarcastic and rude, so SHE would understand the obvious difference, and not make the same mistake. So going from your reply we should all end our replies with 'in case of any misinterpretation of any reply please accept my sincere applogy'.

Link to comment
Share on other sites

No, you don't need to preemptively apologize. But in the case that somebody misinterprets your post you can reply: "I'm sorry, I did not intend for it to sound offensive" and then make your actual intentions more clear.

 

I'm not sure how you see this response as socially acceptable:

"i just pointef out the FACT that information about removing items IS there, IF you bothered to open your fr$ing eyes and look"

Link to comment
Share on other sites

You left out the important part explaining that 'IF you bothered to open your fr$ing eyes and look' IS what I and anyone else would class as being unacceptable and rude, WHAT i wrote before WAS NOT written as sarcastic or rude, which you agreed, IF she takes every single reply as being from scratch a bitter sarcastic comment, that is what I, and everyone else would have to have, a so-called pre-emptive apology because in her mind and only her mind it IS rude and sarcastic. IN other words LIGHTEN UP and come out of the dark bitter sarcastic world you seem to live in.

Link to comment
Share on other sites

I think this thread is done. Please keep conversation civil and respectful at all time. That goes for all members of the forums.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...