I use this code, and it works, but it only works one time. How come?
<script type="text/javascript">
function goToAnchor(name){
window.location.hash = name;}
</script>
<li onclick="goToAnchor('topp');"><a href="test.html" target="iframetest">Tst</a></li>
The first time your call it, it changes
window.location.hashand causes the browser to scroll to the ID or anchor you specified. The second time,window.location.hashis already set totopp(or whatever you passed togoToAnchorthe first time) and since thehashhasn’t changed the browser doesn’t change the scroll position.There are various ways to fix this:
<a href='#topp'>Topp</a>Use the
scrollIntoViewfunction to scroll to the element you’re targetting: