Spaces:
Running
Running
Update index.html
Browse files- index.html +48 -22
index.html
CHANGED
|
@@ -1,26 +1,52 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
<head>
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
</head>
|
| 7 |
<body>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
/
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
</body>
|
| 26 |
-
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Browser History Demo</title>
|
| 6 |
+
<style>
|
| 7 |
+
body { font-family: sans-serif; text-align: center; margin-top: 50px; }
|
| 8 |
+
code { background-color: #eee; padding: 3px 5px; border-radius: 4px; }
|
| 9 |
+
.warning { color: red; font-weight: bold; }
|
| 10 |
+
</style>
|
| 11 |
</head>
|
| 12 |
<body>
|
| 13 |
+
|
| 14 |
+
<h1>Browser History API Demonstration</h1>
|
| 15 |
+
|
| 16 |
+
<p>
|
| 17 |
+
The script on this page can see the number of pages in your
|
| 18 |
+
<strong>current tab's session history</strong>.
|
| 19 |
+
</p>
|
| 20 |
+
|
| 21 |
+
<h2>Number of pages in this tab's session: <span id="history-length"></span></h2>
|
| 22 |
+
|
| 23 |
+
<p class="warning">
|
| 24 |
+
NOTICE: This script CANNOT see the actual URLs of the pages you have visited.
|
| 25 |
+
<br>
|
| 26 |
+
Accessing that information is blocked by the browser for your privacy.
|
| 27 |
+
</p>
|
| 28 |
+
|
| 29 |
+
<button onclick="history.back()">Go Back</button>
|
| 30 |
+
|
| 31 |
+
<script>
|
| 32 |
+
// Get the element where we will display the history length
|
| 33 |
+
const historyLengthElement = document.getElementById('history-length');
|
| 34 |
+
|
| 35 |
+
// Access the history.length property and display it
|
| 36 |
+
// This is SAFE and does not reveal any private information.
|
| 37 |
+
historyLengthElement.textContent = window.history.length;
|
| 38 |
+
|
| 39 |
+
// The following code is IMPOSSIBLE and will NOT work.
|
| 40 |
+
// It is just an example of what browsers prevent.
|
| 41 |
+
/*
|
| 42 |
+
for (let i = 0; i < history.length; i++) {
|
| 43 |
+
// This line would cause a security error if it were possible.
|
| 44 |
+
// You CANNOT get the URL from a history entry.
|
| 45 |
+
console.log(history.item(i)); // This doesn't exist
|
| 46 |
+
console.log(history[i]); // This doesn't work
|
| 47 |
+
}
|
| 48 |
+
*/
|
| 49 |
+
</script>
|
| 50 |
+
|
| 51 |
</body>
|
| 52 |
+
</html>
|