From fc8976565cc9d488d32544c932c3b39566388742 Mon Sep 17 00:00:00 2001 From: Rakshitha N Date: Mon, 9 Feb 2026 21:58:34 +0530 Subject: [PATCH] Added 404 page --- public/404-handler.js | 139 ++++++++++++++ public/404.html | 424 ++++++++++++++++++++++++++++++++++++++++++ public/login.html | 46 ++++- public/signup.html | 45 +++++ 4 files changed, 653 insertions(+), 1 deletion(-) create mode 100644 public/404-handler.js create mode 100644 public/404.html diff --git a/public/404-handler.js b/public/404-handler.js new file mode 100644 index 00000000..71263e0b --- /dev/null +++ b/public/404-handler.js @@ -0,0 +1,139 @@ +// 404-handler.js - Add this to all your HTML files + +// List of all valid pages in your project +const VALID_PAGES = [ + 'index.html', + 'signup.html', + 'login.html', + 'dashboard.html', + 'analytics.html', + 'goals.html', + 'settings.html', + 'Monthlysummary.html', + 'CurrencyConverter.html', + 'feedback.html', + 'schemes.html', + 'AboutUs.html', + 'PrivacyPolicy.html', + 'terms_service.html', + 'Help-Center.html', + '404.html' +]; + +// Don't run on the 404 page itself +if (!window.location.pathname.includes('404.html')) { + document.addEventListener('DOMContentLoaded', function() { + + // ========== 1. HANDLE LINK CLICKS ========== + document.addEventListener('click', async function(e) { + const link = e.target.closest('a[href]'); + if (!link) return; + + const href = link.getAttribute('href'); + + // Skip external links + if (href.startsWith('http') && !href.startsWith(window.location.origin)) { + return; + } + + // Skip anchors, mailto, etc. + if (href.startsWith('#') || href.startsWith('mailto:') || href.startsWith('tel:')) { + return; + } + + // Only handle .html files + if (href.endsWith('.html') || href.includes('.html?')) { + e.preventDefault(); + + // Extract filename + const filename = href.split('/').pop().split('?')[0]; + + // Quick check: Is this a valid page? + if (!VALID_PAGES.includes(filename)) { + // Not a valid page, go to 404 + sessionStorage.setItem('attemptedUrl', href); + window.location.href = '404.html'; + return; + } + + // Show loading state + link.classList.add('loading'); + + try { + // Try to fetch the page + const response = await fetch(href, { method: 'HEAD' }); + + if (response.ok) { + // Page exists, navigate normally + window.location.href = href; + } else { + // Page not found + sessionStorage.setItem('attemptedUrl', href); + window.location.href = '404.html'; + } + } catch (error) { + // Network error or other issue + console.error('Navigation error:', error); + sessionStorage.setItem('attemptedUrl', href); + window.location.href = '404.html'; + } + } + }); + + // ========== 2. CHECK CURRENT PAGE ========== + // Check if current page is valid + const currentPage = window.location.pathname.split('/').pop() || 'index.html'; + + // Don't check index, login, signup pages + if (!['', 'index.html', 'login.html', 'signup.html'].includes(currentPage)) { + if (!VALID_PAGES.includes(currentPage)) { + // Current page is not valid, redirect to 404 + setTimeout(() => { + sessionStorage.setItem('attemptedUrl', window.location.href); + window.location.href = '404.html'; + }, 100); + } + } + + // ========== 3. HANDLE BROWSER NAVIGATION ========== + window.addEventListener('popstate', function() { + // Check page when user goes back/forward + setTimeout(() => { + const page = window.location.pathname.split('/').pop() || 'index.html'; + if (!VALID_PAGES.includes(page) && !page.includes('?')) { + sessionStorage.setItem('attemptedUrl', window.location.href); + window.location.href = '404.html'; + } + }, 50); + }); + }); +} + +// Add loading animation styles +const style = document.createElement('style'); +style.textContent = ` + a.loading { + position: relative; + pointer-events: none; + opacity: 0.7; + } + + a.loading::after { + content: ''; + position: absolute; + top: 50%; + left: 50%; + width: 16px; + height: 16px; + margin: -8px 0 0 -8px; + border: 2px solid rgba(100, 255, 218, 0.3); + border-top-color: #64ffda; + border-radius: 50%; + animation: spin 0.6s linear infinite; + } + + @keyframes spin { + to { transform: rotate(360deg); } + } +`; +document.head.appendChild(style); \ No newline at end of file diff --git a/public/404.html b/public/404.html new file mode 100644 index 00000000..5609baa7 --- /dev/null +++ b/public/404.html @@ -0,0 +1,424 @@ + + + + + + + + 404 - Page Not Found | ExpenseFlow + + + + + + + + + +
+
+ +
+ +

404

+

Oops! Page Lost in Space

+ +

+ The page you're looking for seems to have drifted into the digital void. + It might have been moved, deleted, or perhaps never existed in this universe. +

+ +
+
+
10K+
+
Active Users
+
+
+
₹50M+
+
Tracked
+
+
+
99.9%
+
Uptime
+
+
+ + +
+ + + + + + \ No newline at end of file diff --git a/public/login.html b/public/login.html index 666cdee3..d309537b 100644 --- a/public/login.html +++ b/public/login.html @@ -1236,7 +1236,51 @@

Company

- + + + + + + diff --git a/public/signup.html b/public/signup.html index 16bdad0b..60ae4add 100644 --- a/public/signup.html +++ b/public/signup.html @@ -604,5 +604,50 @@

Company

+ + + + + + \ No newline at end of file