Suppose 5 html files (A, B, C, D, and E) comprise a website. File A is the index.html file. File C contains a Javascript section (i.e., <script> ... </script>). While I’m within the Javascript section, I want to transfer control to html file D. I tried to do it with (window.location = 'File D.html'). That trial failed, for it transferred control to File A—not to file D. Is there any way to get the result that I want, which is to transfer control from within the Javascript section to an html file that is not the site’s index.html file? If a way exists, then please describe it to me. To follow is the code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enter Passcode</title>
<link rel="stylesheet" href="Styling.css">
<script src="script.js"></script>
</head>
<body>
<!--For the screen's top line. Create a 3-cell container. In cell 1, put a link to my home page. In cell 2, put the page's title. Leave cell 3 empty. -->
<div id="textbox">
<div class="left-cell"> </div>
<div class="middle-cell">Enter Passcode</div>
<div class="right-cell"> </div>
</div>
<br /><br /><br />
<script>
let i=0, PC='' // Initialize variable i (the counter) and PC, which holds the passcode entered.
do { // Begin a Do ... While i<3 loop.
PC = prompt("Please enter your passcode exactly as I gave it to you.","");
// Test PC to see what the LA did The prompt box has 2 buttons to hit: Cancel & OK. Cancel returns null. OK returns whatever
// he entered in the prompt box.
if (PC == null)
(window.location = 'index.html') // He hit "Cancel"; so return to home page.
// He hit "OK"; so he entered a passcode. Did he enter the right one?
else if (PC == "Zeta")
(window.location = 'Choose_Book.html') // Correct passcode entered; so launch the choose-book code.
else
i = i + 1 // A bad passcode was entered; so increment i
}
while (i<3)
//Control arrives here only if i=3 (3 consecutive bad passcodes entered).
alert("3 bad passcodes were entered. Hit the OK button to return to the home page.");
window.location = 'index.html'
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enter Passcode</title>
<link rel="stylesheet" href="Styling.css">
<script src="script.js"></script>
</head>
<body>
<!--For the screen's top line. Create a 3-cell container. In cell 1, put a link to my home page. In cell 2, put the page's title. Leave cell 3 empty. -->
<div id="textbox">
<div class="left-cell"> </div>
<div class="middle-cell">Enter Passcode</div>
<div class="right-cell"> </div>
</div>
<br /><br /><br />
<script>
let i=0, PC='' // Initialize variable i (the counter) and PC, which holds the passcode entered.
do { // Begin a Do ... While i<3 loop.
PC = prompt("Please enter your passcode exactly as I gave it to you.","");
// Test PC to see what the LA did The prompt box has 2 buttons to hit: Cancel & OK. Cancel returns null. OK returns whatever
// he entered in the prompt box.
if (PC == null)
(window.location = 'index.html') // He hit "Cancel"; so return to home page.
// He hit "OK"; so he entered a passcode. Did he enter the right one?
else if (PC == "Zeta")
(window.location = 'Choose_Book.html') // Correct passcode entered; so launch the choose-book code.
else
i = i + 1 // A bad passcode was entered; so increment i
}
while (i<3)
//Control arrives here only if i=3 (3 consecutive bad passcodes entered).
alert("3 bad passcodes were entered. Hit the OK button to return to the home page.");
window.location = 'index.html'
</script>
</body>
</html>