Home > Net >  HTML Anchor doesn't jump to section with url
HTML Anchor doesn't jump to section with url

Time:01-31

I have a blog-site, which is full of text, therefore i use sections.

my code:


<a href="#test">Test</a>

....

 <h3 id="test">Test</h3>

When I click on the anchor, it works, but if I use the URL, i cannot get to the section, only to the top of the site.

What I want:

mysite.com/site1: <a href="/site2#test > Test</a>

mysite.com/site2 <h3 id="test"> Test </h3>

Why does it not jump to the section?

CodePudding user response:

Have you tried using two # for the anchor?

<a href="/site2##test>Test</a>

It seems Chrome sometimes has it's issues with anchor links and this may help (at least works on my machine)

(possibly related to Anchor <a> tags not working in chrome when using #)

CodePudding user response:

One way to solve this might be using window.location in javascript

<script>
        function goToSite2Section() {
            window.location = '/site2#test';
        }
</script>
<a href="#" onclick="goToSite2Section()"> Test</a>
  • Related