Jump to content

Storing options between pages


Recommended Posts

I have a 'status' div on most the pages of the home project I'm working on (trying to learn Laravel) and I wanted to be able to hide or show this bit.  

The way I've done this is using a menu option with checkbox which when clicked does the appropriate bits of hiding and showing the div and adjusting the size of the other div to fill the screen.  Firstly - I'm assuming this is a reasonable approach, please let me know if there is a better way.

Secondly - as expected - when I click on a link to go to another page, this option was reset and therefore it lost the last screens selection.  Sooooo... I'm using

 localStorage.setItem();

to store the value, which is used in the JS when I click on the check box and the value retrieved on start of the screen display to allow me to set it as it was on the last page.  Again - is this solution OK/Good/Bad/Spawn of the Devil?

It's achieved what I wanted - but is it any good ? Any other suggestions would be welcome.

Link to post
Share on other sites

LocalStorage is a bit much, and it's restricted to just client-side processing. I'd put it in a cookie, which you could use with your PHP (to render the page correctly initially) and the Javascript (to set the value when it changes, and get if needed).

Link to post
Share on other sites

I've read about the differences of local storage and cookies and there seems to be little difference technically.  Main things seem to be client side limitation, timeouts, older browser compatibility and data volumes.  TBH I don't care about server side processing of this field, there isn't going to be much data I use for this sort of thing and I don't need timeouts.

From the responses I've had it's more about what people would normally do as opposed to what you can do - which is more useful than anything ATM.

Link to post
Share on other sites

Local storage is a fine replacement for cookies if you're only interested in newer browsers that support it. Might even work a bit better by avoiding all the cookie clearing/scrubbing people like to do.

 

Session storage is another option if you don't need the value to persist across different browser sessions.

Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.