Write a code using for the following: Include a header that is Your Name, Visit Tracker Complete the code in a single .htm file On the first visit to the page, display a message indicating such (see example below) On each subsequent visit (or refresh) of the page, display a message indicating the day, date, and time of the previous visit (see example below) Include your name as part of the message
Write a code using for the following: Include a header that is Your Name, Visit Tracker Complete the code in a single .htm file On the first visit to the page, display a message indicating such (see example below) On each subsequent visit (or refresh) of the page, display a message indicating the day, date, and time of the previous visit (see example below) Include your name as part of the message
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Write a code using for the following:
Include a header that is Your Name, Visit Tracker
Complete the code in a single .htm file
On the first visit to the page, display a message indicating such (see example below)
On each subsequent visit (or refresh) of the page, display a message indicating the day, date, and time of the previous visit (see example below)
Include your name as part of the message
Expert Solution
Step 1
Please note that it may not work if your browser has local cookies support turned off
You can put your name wherever "Your Name" appears in this code.
index.htm
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Name</title>
</head>
<body>
<h3>Your Name, <span id="message"> </span> </h3>
<p id="last_visit_message"> </p>
<script type="text/javascript">
function setCookie(cookie_name, cookie_value, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cookie_name + "=" + cookie_value + ";" + expires + ";" + "SameSite=Lax";
}
function getCookie(cookie_name) {
var name = cookie_name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function checkCookie() {
var user = getCookie("username");
var visits = parseInt(getCookie("counter"));
var last_visit = getCookie("last_visit");
if (user != "") {
visits = parseInt(visits) + 1;
document.querySelector("#message").innerHTML = "you have visited this page " + visits + " times.";
document.querySelector("#last_visit_message").innerHTML = "Your last visit was at " + last_visit.toString();
setCookie("username", user, 365);
setCookie("counter", visits, 365);
} else {
user = "Your Name";
visits = 1;
last_visit = new Date();
document.querySelector("#message").innerHTML = "this is your first visit.";
if (user != "" && user != null) {
setCookie("username", user, 365);
setCookie("counter", visits, 365);
}
}
setCookie("last_visit", new Date(), 365);
}
checkCookie();
var all_cookies = document.cookie;
console.log(all_cookies);
</script>
</body>
</html>
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education