Reputation: 1192
I am having this page example.com/index.php
with different sections. Each section can be accessed by the following link.
example.com/index.php#first
example.com/index.php#second
When the user gets to the page example.com/index.php
, he is supposed to be directed to the first section so I used this code:
<script> window.location = "#first"; </script>
Any time I try to access example.com/index.php#second
I am directed to the first section (example.com/index.php#first
), instead of being directed to the second section.
Kindly help me solve the issue. Sorry I am not a native english speaker.
Upvotes: 0
Views: 1670
Reputation: 4654
I think in this case it's a matter of using a simple conditional:
if(!window.location.hash) {
window.location.hash = '#first'
}
Upvotes: 4