Reload on anchor link click
If a certain link is clicked, reload the page and jump to that hash.
by Jon Fuller
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<nav><a href="https://fiddle.jshell.net/_display/#link1">Link1</a> | <a href="https://fiddle.jshell.net/_display/#link2">Link2</a> | <a href="https://fiddle.jshell.net/_display/#link3">Link3</a></nav>
<div id="link1">
Content 1
</div>
<div id="link2">
Content 2
</div>
<div id="link3">
Content 3
</div>
CSS
body {
margin: 0;
padding: 0;
}
nav {
position: fixed;
background: rgba(255,255,255,0.8);
padding: 40px;
width: 100%;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
div {
height: 100vh;
background-color: gray;
border: 4px solid green;
padding: 100px 40px;
color: white;
font-family: sans-serif;
box-sizing: border-box;
}
JavaScript
//force href with specific link to reload if is clicked on this page
jQuery('a[href="https://fiddle.jshell.net/_display/#link1"]').click(function(){
window.location.href = (jQuery(event.currentTarget).attr("href"));
window.location.reload(true);
})
jQuery('a[href="https://fiddle.jshell.net/_display/#link2"]').click(function(){
window.location.href = (jQuery(event.currentTarget).attr("href"));
window.location.reload(true);
})
jQuery('a[href="https://fiddle.jshell.net/_display/#link3"]').click(function(){
window.location.href = (jQuery(event.currentTarget).attr("href"));
window.location.reload(true);
})