skaterdav85 Posted November 24, 2008 Share Posted November 24, 2008 So i created 2 links that give the user 2 options of different style sheets, and i save whatever style sheet chosen as a cookie. However, how do i read those style sheets for the rest of my site? this is the code where it saves the style sheet chosen as a cookie://initial style sheet<link rel="stylesheet" href="style_1.css" id="stylesheet">//saves the chosen style sheet as a cookiefunction changeStyle(whichsheet) {document.cookie = document.getElementById('stylesheet').href = whichsheet;}//2 links for different style sheet options<a href="#" onClick="changeStyle('style_2.css');">style sheet 2</a><a href="#" onClick="changeStyle('style_3.css');">style sheet 3</a>Thanks! Link to comment Share on other sites More sharing options...
jeffman Posted November 24, 2008 Share Posted November 24, 2008 There's a decent cookie tutorial here: http://www.w3schools.com/JS/js_cookies.asp Link to comment Share on other sites More sharing options...
rnd me Posted November 25, 2008 Share Posted November 25, 2008 function getCookie(k) {var d = document.cookie || "";var pairs = d.split(k + "=");if (pairs && pairs[1]) {return unescape(pairs[1].split(";")[0]);}};function setCookie(nm, valu) {var e2 = (new Date(2019, 1, 1)).toGMTString();document.cookie = nm + "=" + escape(valu) + "; expires=" + e2;}function changeStyle(whichsheet) { whichsheet = whichsheet || 'style_1.css'; //set up a first-visit default setCookie( "lastCSS", whichsheet);}<body onload="changeStyle(getCookie('lastCSS'));"> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.