Updated example,
In the starting page:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="stylesheet" type="text/css" href="example.css" />
<style>
*, *:after, *::before{box-sizing: border-box;tap-highlight-color: rgba(0,0,0,0);tap-highlight-color: transparent;touch-callout: none;focus-ring-color:rgba(0,0,0,0);user-select: none;outline: none;text-decoration: none;}
html, body{background: #EEE;color: #333;font: normal 15px Arial;line-height: 1.4;min-height: 100vh;width: 100vw;padding: 4vw;margin: 0;display: flex;position: relative;flex-direction: column;align-items: center;justify-content: space-around;z-index: 0;}
main{background: #EEE;color: #333;min-height: 80px;width: 80%;padding: 4vw;margin: 0;display: flex;position: relative;flex-direction: column;align-items: center;justify-content: space-around;z-index: 1;border: 4px double #777;border-radius: 8px;}
h2{font-size: 26px;}
p{font-size: 18px;}
.buttons-container{background: #EEE;color: #333;min-height: 98px;width: 100%;display: flex;display: box;position: relative;align-items: center;flex-direction: column;justify-content: space-between;z-index: 2;}
a{background: #444;color: #EEE;font: bold 16px Arial;text-align: center;line-height: 38px;height: 40px;width: 70%;margin: 0;display: block;position: relative;border: 2px solid #777;border-radius: 8px;}
</style>
<script src="example.js"></script>
<!-- Script below is not needed, it’s only for testing the variable, load the script at "body" onload then print the saved variable at div "#print-saved-value" -->
<!-- Session Storage is for temporary store until user’s browser is closed -->
<!-- Local Storage is for lasting store even after user’s browser is closed -->
<script>
function printingAorB(){
if (typeof(Storage) !== "undefined"){
localStorage.getItem("userChoice");
if (localStorage.userChoice === "isA"){document.getElementById("print-saved-value").innerHTML = "User choose A";}
else if (localStorage.userChoice === "B"){document.getElementById("print-saved-value").innerHTML = "User choose B";}
else {document.getElementById("print-saved-value").innerHTML = "Choice is blank";}
}
}
</script>
</head>
<body onload="printingAorB()">
<main>
<h2>The Start Page</h2>
<hr/>
<p>Below are option A and B. By clicking a link, the link will saving either variable "isA" or "B" and open "index2.html" page.<br><br><span style="color:#777">Session Storage is for temporary store until user’s browser is closed, while Local Storage is for lasting store even after user’s browser is closed.</span></p>
<div class="buttons-container">
<!-- Saving the variable to be used for next session, the index2.html -->
<a onclick="localStorage.setItem('userChoice', 'isA');" href="index2.html">A is good</a>
<a onclick="localStorage.setItem('userChoice', 'B');" href="index2.html">B is not bad</a>
</div>
<div id="print-saved-value"></div>
</main>
</body>
</html>
Then the page before the destination, say it is "index2.html",
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<style>*, *:after, *::before{box-sizing: border-box;tap-highlight-color: rgba(0,0,0,0);tap-highlight-color: transparent;touch-callout: none;focus-ring-color:rgba(0,0,0,0);user-select: none;outline: none;text-decoration: none;}html, body{background: #EEE;color: #333;font: normal 15px Arial;line-height: 1.4;min-height: 100vh;width: 100vw;padding: 4vw;margin: 0;display: flex;position: relative;flex-direction: column;align-items: center;justify-content: space-around;z-index: 0;}main{background: #EEE;color: #333;min-height: 80px;width: 80%;padding: 4vw;margin: 0;display: flex;position: relative;flex-direction: column;align-items: center;justify-content: space-around;z-index: 1;border: 4px double #777;border-radius: 8px;}h2{font-size: 26px;}p{font-size: 18px;}.buttons-container{background: #EEE;color: #333;min-height: 98px;width: 100%;display: flex;display: box;position: relative;align-items: center;flex-direction: column;justify-content: space-between;z-index: 2;}a{background: #444;color: #EEE;font: bold 16px Arial;text-align: center;line-height: 38px;height: 40px;width: 70%;margin: 0;display: block;position: relative;border: 2px solid #777;border-radius: 8px;}</style>
<!-- Script is loaded at body onload but can be placed at page’s bottom. Used by Version 1. -->
<script>
/* Version 1: load the saved variable then changing the landing page href based on the saved data. */
function changeLinks(){
/* Button/choice 1 */
document.getElementById("choice-1").onclick = function(){
localStorage.getItem("userChoice");
var destination1 = document.getElementById("choice-1");
if (localStorage.userChoice === "isA"){
destination1.setAttribute("href", "page_1_a.html");
} else {destination1.setAttribute("href", "page_1_b.html");
} return false;
}
/* Button/choice 2 */
document.getElementById("choice-2").onclick = function(){
localStorage.getItem("userChoice");
var destination2 = document.getElementById("choice-2");
if (localStorage.userChoice === "isA"){
destination2.setAttribute("onclick", "location.href='page_2_a.html'");
} else {destination2.setAttribute("onclick", "location.href='page_2_b.html'");
} return false;
}
}
</script>
</head>
<body onload="changeLinks()">
<main>
<h2>The Bridge Version 1</h2>
<hr/>
<p>Below are Choice 1 to 2 (before 3 and the rest). The landing pages for this will be like: page_1_a.html, page_1_b.html, page_2_a.html, and so on...</p>
<div class="buttons-container">
<a id="choice-1">Choice 1</a>
<a id="choice-2">Choice 2</a>
</div>
</main>
<main>
<h2>The Bridge Version 2</h2>
<hr/>
<p>Below are Choice 1 to 2 (before 3 to the rest). The script at landing pages will determine either is it A or B.</p>
<div class="buttons-container">
<a id="choice-1" href="page_1.html">Choice 1</a>
<a id="choice-2" href="page_2.html">Choice 2</a>
</div>
</main>
</body>
</html>
And an example of page _1.html , when using 2nd version.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<style>*, *:after, *::before{box-sizing: border-box;tap-highlight-color: rgba(0,0,0,0);tap-highlight-color: transparent;touch-callout: none;focus-ring-color:rgba(0,0,0,0);user-select: none;outline: none;text-decoration: none;}html, body{background: #EEE;color: #333;font: normal 15px Arial;line-height: 1.4;min-height: 100vh;width: 100vw;padding: 4vw;margin: 0;display: flex;position: relative;flex-direction: column;align-items: center;justify-content: space-around;z-index: 0;}main{background: #EEE;color: #333;min-height: 80px;width: 80%;padding: 4vw;margin: 0;display: flex;position: relative;flex-direction: column;align-items: center;justify-content: space-around;z-index: 1;border: 4px double #777;border-radius: 8px;}h2{font-size: 26px;}p{font-size: 18px;}.buttons-container{background: #EEE;color: #333;min-height: 98px;width: 100%;display: flex;display: box;position: relative;align-items: center;flex-direction: column;justify-content: space-between;z-index: 2;}a{background: #444;color: #EEE;font: bold 16px Arial;text-align: center;line-height: 38px;height: 40px;width: 70%;margin: 0;display: block;position: relative;border: 2px solid #777;border-radius: 8px;}</style>
<!-- Showing content A or content B -->
<script>
function determine2ShowingAorB(){
if (typeof(Storage) !== "undefined"){
localStorage.getItem("userChoice");
if (localStorage.userChoice === "isA"){
document.getElementById("content-a").style.display = "block";
} else if (localStorage.userChoice === "isA"){
document.getElementById("content-b").style.display = "block";
} else {}
}
}
</script>
<style>
#content-a, #content-b{display: none;}
</style>
</head>
<body onload="determine2ShowingAorB()">
<main>
<h2>The Landing, Page 1</h2>
<hr/>
<p>Below will be content of A or B. If there’s nothing, then the variable is not loaded.</p>
<div id="content-a">
<h1>This is content A</h1>
</div>
<div id="content-b">
<h1>This is content B</h1>
</div>
</main>
</body>
</html>