Advertisement
Guest User

Untitled

a guest
May 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <p>CLICK TO CHANGE BACKGROUND COLOUR FOR MORE PLEASENT VIEWING.</p>
  2.  
  3.  
  4.  
  5. <button onclick="myFunction()">Try it</button>
  6.  
  7. <script>
  8.  
  9. window.onclick = myFunction;
  10.  
  11.  
  12.  
  13. function myFunction() {
  14.  
  15. document.getElementsByTagName("BODY")[0].style.backgroundColor = "white";
  16.  
  17. }
  18.  
  19. </script>
  20.  
  21.  
  22.  
  23. </body>
  24.  
  25. </html>
  26. <html>
  27.  
  28. <head>
  29.  
  30. <script>
  31.  
  32. function setCookie(cname,cvalue,exdays) {
  33.  
  34. var d = new Date();
  35.  
  36. d.setTime(d.getTime() + (exdays*24*60*60*1000));
  37.  
  38. var expires = "expires=" + d.toGMTString();
  39.  
  40. document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  41.  
  42. }
  43.  
  44.  
  45.  
  46. function getCookie(cname) {
  47.  
  48. var name = cname + "=";
  49.  
  50. var decodedCookie = decodeURIComponent(document.cookie);
  51.  
  52. var ca = decodedCookie.split(';');
  53.  
  54. for(var i = 0; i < ca.length; i++) {
  55.  
  56. var c = ca[i];
  57.  
  58. while (c.charAt(0) == ' ') {
  59.  
  60. c = c.substring(1);
  61.  
  62. }
  63.  
  64. if (c.indexOf(name) == 0) {
  65.  
  66. return c.substring(name.length, c.length);
  67.  
  68. }
  69.  
  70. }
  71.  
  72. return "";
  73.  
  74. }
  75.  
  76.  
  77.  
  78. function checkCookie() {
  79.  
  80. var user=getCookie("username");
  81.  
  82. if (user != "") {
  83.  
  84. alert("Welcome again " + user);
  85.  
  86. } else {
  87.  
  88. user = prompt("Please enter your name:","");
  89.  
  90. if (user != "" && user != null) {
  91.  
  92. setCookie("username", user, 30);
  93.  
  94. }
  95.  
  96. }
  97.  
  98. }
  99.  
  100. </script>
  101.  
  102. </head>
  103.  
  104.  
  105.  
  106. <body onload="checkCookie()"></body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement