I have a big page with over 6000 anchors like id="#0000001"
.
to navigate I added a small search form, fixed to the top right corner and use JS to switch location on the document.
After each search, the hole page will reload (around 4,5MB).
I would like to navigate/scroll up and down without reloading. The same as it works clicking to the simple but long link-list.
It must also work offline so HTML, CSS and JS must be in the same document.
solution code (7.5.2020) thanks to all, it works with this code. I also changed <form>
to <div>
used form:
<div id="suchForm" class="hide_on_print">
<input id="eingabeNr" name="suchFeld" type="text" size="10" value="">
<button type="button" class="strongSuche" id="strongSucheID"></button>
</div>
the hole JS (search start by keypress-'ENTER' or click the button:
<script>
window.addEventListener("load", function() {
// press "Enter" in the search field starts searching Strong
document.getElementById("eingabeNr").addEventListener('keypress', (e) => {
if(e.keyCode == 13){
//alert("You pressed \'Enter\'-Key.");
geheZuStrong();
}
});
// "Click" Button starts Strong search
document.getElementById('strongSucheID').addEventListener('click', (e) => {
e.preventDefault();
//alert("You pressed search button"".);
geheZuStrong();
});
// "creates" an ancor and move to it
function geheZuStrong() {
//alert("function: \'geheZuStrong\' running now");
let gesNr = document.getElementById("eingabeNr").value;
switch(gesNr.length) {
case (1):
window.location.hash = "#000000" + gesNr;
break;
case (2):
window.location.hash = "#00000" + gesNr;
break;
case (3):
window.location.hash = "#0000" + gesNr;
break;
case (4):
window.location.hash = "#000" + gesNr;
break;
default:
// Anweisungsblock alternativ
alert('Strong Nummern sind im Bereich 1 bis 6020. Ihre Eingabe war: ' + strongLänge);
}
}
}, false);
</script>
and the long link list with 6020 entries (to replace):
<a href="#0000001">1</a> -
<a href="#0000002">2</a> -
...
<a href="#0006020">6020</a> -