diff --git a/assets/html_files/page_not_found.html b/assets/html_files/page_not_found.html
new file mode 100644
index 0000000..f20af36
--- /dev/null
+++ b/assets/html_files/page_not_found.html
@@ -0,0 +1,89 @@
+
+
+
+
+
+ 404 - Page Not Found
+
+
+
+
+
404
+
Oops! Page Not Found
+
The page you're looking for doesn't exist or has been moved.
+
+
+
diff --git a/script.js b/script.js
index 18cd3e3..77b212a 100644
--- a/script.js
+++ b/script.js
@@ -180,3 +180,36 @@ const subtitleOptions = {
};
const typedSubtitle = new Typed('#animated-text', subtitleOptions);
});
+
+document.querySelectorAll('a').forEach(anchor => {
+ anchor.addEventListener('click', function (e) {
+ const href = this.getAttribute('href');
+
+ // Ignore external links, hash links, mailto, tel, or javascript:void(0)
+ if (
+ !href ||
+ href.startsWith('http') ||
+ href.startsWith('#') ||
+ href.startsWith('mailto:') ||
+ href.startsWith('tel:') ||
+ href.startsWith('javascript:')
+ ) return;
+
+ e.preventDefault();
+
+ fetch(href, { method: 'HEAD' }) // Use HEAD for faster check
+ .then(response => {
+ if (!response.ok) {
+ // If response status is not 2xx
+ window.location.href = 'page_not_found.html';
+ } else {
+ window.location.href = href;
+ }
+ })
+ .catch(() => {
+ // If fetch fails (e.g., network error)
+ window.location.href = 'page_not_found.html';
+ });
+ });
+});
+