I need help with a script that will only refresh the page when a specific link is clicked. Currently, the script is running on page load instead of waiting for the click event.
As someone who is not familiar with JavaScript, I am struggling to figure this out on my own. Any assistance would be greatly appreciated...
Edit: I made some changes to my code, but now it's not executing at all - neither on page load nor on click.
Edit 2: This issue is part of a larger problem. You can observe the effect by visiting the following website:
Once on the site, use the dropdown menu under 'productions' and select 'Edition Klangidee'. The page loads correctly and scrolls to the anchor. However, if you click 'Edition Klangidee' again, the cookie bar seems to displace all content by its own height. A simple reload fixes the layout.
The cookie bar is generated by a script that I did not create myself (as I lack the skill to do so) but downloaded.
In my opinion, the best solution would be to modify the JavaScript file. Since I lack the required knowledge, I thought an auto-reload feature could serve as a temporary workaround.
Perhaps this additional information provides some context...
script:
=======
<script type="text/javascript">
;(function fun() {
var reloads = [1000, 3000],
storageKey = 'reloadIndex',
reloadIndex = parseInt(localStorage.getItem(storageKey), 10) || 0;
if (reloadIndex >= reloads.length || isNaN(reloadIndex)) {
localStorage.removeItem(storageKey);
return;
}
setTimeout(function(){
window.location.reload();
}, reloads[reloadIndex]);
localStorage.setItem(storageKey, parseInt(reloadIndex, 10) + 1);
}
</script>
html-code:
==========
<a href="https://mylink#myanchor" target="_self" id="ek_reload" onclick="fun()">MyMenuItem</a>