-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrouter.js
72 lines (61 loc) · 2.65 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function handleButtonClick(page) {
window.location.hash = page;
}
// function Route(){
// window.location.href = "./startup_page/pg.html";
// }
document.getElementById("voterBtn").addEventListener("click", function() {
console.log("LOL");
// Directly navigate to the "voterlogin.html" page
window.location.href = "./voter_login/voterlogin.html";
});
document.getElementById("candidateBtn").addEventListener("click", function() {
// Directly navigate to the "voterlogin.html" page
window.location.href = "./candidate_page/candidate.html";
});
document.getElementById("voterControllerBtn").addEventListener("click", function() {
// Directly navigate to the "voterlogin.html" page
window.location.href = "./voter_controller/controlller.html";
});
document.getElementById("candidateBtn").addEventListener("click", function() {
handleButtonClick("candidate");
});
document.getElementById("voterControllerBtn").addEventListener("click", function() {
handleButtonClick("voterController");
});
function loadPageContent() {
const hash = window.location.hash.substring(1);
const contentDiv = document.getElementById("content");
switch(hash) {
case "voter":
// Load "voterlogin.html" content dynamically without page reload
fetch("voterlogin/voterlogin.html")
.then(response => response.text())
.then(html => contentDiv.innerHTML = html)
.catch(error => console.error('Error fetching voter login:', error));
break;
case "candidate":
// Load content for "candidate" route
//contentDiv.innerHTML = "Candidate content"; // Update with actual content loading logic
break;
case "voterController":
// Load content for "voterController" route
// contentDiv.innerHTML = "Voter controller content"; // Update with actual content loading logic
break;
default:
// Handle other cases or default behavior
// contentDiv.innerHTML = "Default content"; // Update with actual default content
break;
}
}
window.addEventListener("hashchange", loadPageContent);
window.addEventListener("load", loadPageContent);
//document.getElementById("voter-login-form").addEventListener("submit", function(event) {
// Prevent the default form submission behavior
// event.preventDefault();
// Get the voter ID input value
//const voterId = document.getElementById("voter-id").value;
// Perform any necessary validation of the voter ID here
// Redirect the user to voting.html
//window.location.href = "./voting_page/voting.html";
//});