{"id":6909,"date":"2014-04-12T12:19:50","date_gmt":"2014-04-12T11:19:50","guid":{"rendered":"http:\/\/www.wjst.de\/blog\/?p=6909"},"modified":"2014-04-12T14:33:00","modified_gmt":"2014-04-12T13:33:00","slug":"let-your-visitors-switch-background-color","status":"publish","type":"post","link":"https:\/\/www.wjst.de\/blog\/sciencesurf\/2014\/04\/let-your-visitors-switch-background-color\/","title":{"rendered":"Let your visitors switch background color"},"content":{"rendered":"<p>There seem to be million of ways to do that &#8211; here is the most parsimonious solution that works for me even under difficult conditions and in different browsers.<\/p>\n<pre class=\"brush: php; light: true; title: ; notranslate\" title=\"\">\r\n\/\/ should be run in a $(document).ready(function(){ bracket });\r\n\/\/ if there is no cookie we set one\r\nif (document.cookie.indexOf(&quot;color&quot;)!== -1 {\r\n  document.cookie = &quot;color=white&quot;;\r\n}\r\n\/\/ we need a body class without any background definition\r\n\/\/ and a class for body.black that has background:black\r\nif (document.cookie.indexOf(&quot;black&quot;) === -1) {\r\n  \/\/ switch to the new .black class\r\n  $(&quot;body&quot;).toggleClass(&quot;black&quot;);\r\n  \/\/ this is also possible in the iframe\r\n  $(#iframe&quot;).contents().find(&quot;body&quot;).toggleClass(&quot;black&quot;);\r\n}\r\n\/\/ link or whatever is being clicked for the effect\r\n$(&quot;.place&quot;).click(function () {\r\nif (document.cookie.indexOf(&quot;white&quot;) !== -1) {\r\n  document.cookie = &quot;color=black&quot;;\r\n}\r\nelse {\r\n  document.cookie = &quot;color=white&quot;;\r\n}\r\n\/\/ reload page with a small delay\r\nsetTimeout( function() { location.reload() }, 250 );\r\n<\/pre>\n\n<p>&nbsp;<\/p>\n<div class=\"bottom-note\">\n  <span class=\"mod1\">CC-BY-NC Science Surf , accessed 07.04.2026<\/span>\n <\/div>","protected":false},"excerpt":{"rendered":"<p>There seem to be million of ways to do that &#8211; here is the most parsimonious solution that works for me even under difficult conditions and in different browsers. \/\/ should be run in a $(document).ready(function(){ bracket }); \/\/ if there is no cookie we set one if (document.cookie.indexOf(&quot;color&quot;)!== -1 { document.cookie = &quot;color=white&quot;; } &hellip; <a href=\"https:\/\/www.wjst.de\/blog\/sciencesurf\/2014\/04\/let-your-visitors-switch-background-color\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Let your visitors switch background color<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[2848,2847,2822,2826],"class_list":["post-6909","post","type-post","status-publish","format-standard","hentry","category-computer-software","tag-color","tag-cookie","tag-css","tag-jquery"],"_links":{"self":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/6909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/comments?post=6909"}],"version-history":[{"count":11,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/6909\/revisions"}],"predecessor-version":[{"id":6921,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/6909\/revisions\/6921"}],"wp:attachment":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/media?parent=6909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/categories?post=6909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/tags?post=6909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}