Advertisement
FahimFaisal

Cookie_setColor

Oct 11th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.16 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Title</title>
  6.  
  7. </head>
  8. <body>
  9. <p id="1"></p>
  10. <select id="dd1theme" onchange="setColor();">
  11.     <option value="Select Color">Select Color</option>
  12.     <option value="red">Red</option>
  13.     <option value="green">green</option>
  14.     <option value="blue">Blue</option>
  15. </select>
  16.  
  17. <script type="text/javascript">
  18.  
  19.     window.onload = function () {
  20.         if(document.cookie.length!=0){
  21.             var nameValue=document.cookie.split("=");
  22.             document.bgColor=nameValue[1];
  23.             document.getElementById("1").innerHTML=nameValue[1];
  24.             document.getElementById("dd1theme").value=nameValue[1];
  25.  
  26.         }
  27.     }
  28.     function setColor() {
  29.         var selected=document.getElementById("dd1theme").value;
  30.         if(selected != "Select Color" ){
  31.             document.bgColor=selected;
  32.             var d = new Date();
  33.             exdays=10;
  34.             d.setTime(d.getTime() + (exdays*24*60*60*1000));
  35.             var expires = d.toGMTString();
  36.             document.cookie="color="+selected+";expires="+expires;
  37.         }
  38.     }
  39.     </script>
  40.  
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement