Subham9126 commited on
Commit
91ec91c
·
verified ·
1 Parent(s): 5ba081d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +48 -22
index.html CHANGED
@@ -1,26 +1,52 @@
1
- <!doctype html>
2
- <html>
3
  <head>
4
- <meta charset="utf-8" />
5
- <title>Show IP (client-only)</title>
 
 
 
 
 
6
  </head>
7
  <body>
8
- <h1>Your public IP:</h1>
9
- <pre id="ip">loading…</pre>
10
-
11
- <script>
12
- async function showIP() {
13
- try {
14
- const res = await fetch('https://api.ipify.org?format=json');
15
- if (!res.ok) throw new Error('IP service error');
16
- const data = await res.json();
17
- document.getElementById('ip').textContent = data.ip;
18
- } catch (err) {
19
- document.getElementById('ip').textContent = 'Could not determine IP: ' + err;
20
- }
21
- }
22
- // run as page opens
23
- window.addEventListener('DOMContentLoaded', showIP);
24
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>