jquery - How to Keep Cookie Value after page refresh -
i'm creating demo panel users change layout of wordpress theme when arrive @ demo site. user changes value via select drop-down box, , cookie set @ time.
i'm having trouble showing actions want implement after page refreshed. cookie saving it's value, after page refresh css actions not stay in place. i'm not jquery appreciated. here's code:
$('#montage-demo-panel select.body-style-layout').change(function () { // apply cookie $.cookie('body-style-layout', $(this).val(), { path: '/' }); var value = $(this).val(); if (value == 'fixed') { var wrapper = $('#wrapper'); var header = $('#header'); var masthead = $('#masthead'); var branding = $('#branding'); wrapper.removeattr('style'); header.removeattr('style'); masthead.removeattr('style'); branding.removeattr('style'); wrapper.removeclass('wrapper-full purple-header-full'); header.removeclass('header-full'); masthead.removeclass('masthead-full'); branding.removeclass('branding-full'); location.reload(); } else { var wrapper = $('#wrapper'); var header = $('#header'); var masthead = $('#masthead'); var branding = $('#branding'); var mainbg = $('#main-bg'); var access = $('#access'); wrapper.removeclass('purple-header'); wrapper.addclass('wrapper-full purple-header-full'); header.addclass('header-full'); masthead.addclass('masthead-full'); branding.addclass('branding-full'); mainbg.addclass('main-bg-full'); access.addclass('access-full'); // re-fresh page location.reload(); } });
... if you're applying style on change();
event, it's wont affect on page refresh. suggest check cookie value everytime page refresh, like:
$(function(){ var cookieval = $.cookie('cookie-key'); if (cookieval === 'something'){ //here implement style according 'something' } else { //here implement style } });
good luck !!
update :
- place code above anywhere in page;
just set cookie , reload on select change; like:
$('#montage-demo-panel select.body-style-layout').change(function () { $.cookie('body-style-layout', $(this).val(), { path: '/' }); location.reload(); }
done.
Comments
Post a Comment