「javascriptで外部CSSを一つのボタンで動的にon/offでき、その情報をクッキーに保存する、というサンプルを探しています。
ご存知でしたらご教示ください。」
追加要件
・ボタンを押したらサイト全体のCSSが変わる
・動作はIE6以上firefox2以上OPERA9以上
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript"> <!-- var CSSPath = './test.css' ; // CSS ファイルのパス var outerCSS ; function toggleCSS() { outerCSS.disabled = !outerCSS.disabled ; document.cookie = 'outercss = ' + !outerCSS.disabled ; } function getCookie(key) { var cookies = document.cookie.split(';') ; for (var i = 0; i < cookies.length; ++i) { var theCookie = cookies[i].split('=', 2) ; if (theCookie[0] == key) return unescape(theCookie[1]) ; } return undefined ; } onload = function() { outerCSS = document.createElement('link') ; with (outerCSS) { rel = 'stylesheet' ; type = 'text/css' ; href = CSSPath ; } document.getElementsByTagName('head')[0].appendChild(outerCSS) ; outerCSS.disabled = true ; if (getCookie('outercss') == 'true') toggleCSS() ; } //--> </script> </head> <body> <form> <input type="button" onclick="toggleCSS();" value="css ON-OFF" /> </form> </body> </html>