NigelRel3 Posted April 1, 2017 Share Posted April 1, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/303595-storing-options-between-pages/ Share on other sites More sharing options...
emptry Posted April 1, 2017 Share Posted April 1, 2017 cookie? session ? Quote Link to comment https://forums.phpfreaks.com/topic/303595-storing-options-between-pages/#findComment-1544908 Share on other sites More sharing options...
requinix Posted April 1, 2017 Share Posted April 1, 2017 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). Quote Link to comment https://forums.phpfreaks.com/topic/303595-storing-options-between-pages/#findComment-1544910 Share on other sites More sharing options...
NigelRel3 Posted April 2, 2017 Author Share Posted April 2, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/303595-storing-options-between-pages/#findComment-1544941 Share on other sites More sharing options...
kicken Posted April 2, 2017 Share Posted April 2, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/303595-storing-options-between-pages/#findComment-1544952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.