Switch to snapping on another page

I just want to go from one page to a specific point on another

I have a homepage with four sections.

<section>
   <a name="section1"></a>
</section>

<section id="section2">

</section>

<section>
   <a name="section3"></a>
</section>

<section id="section4">

</section>

The functions of sections 2 and 4 on each page, so my navigator looks like this:

<nav>
      <ul>
        <li><a href="index.html#section1">ABOUT</a></li>
        <li><a href="#section2">APARTMENTS</a></li>
        <li><a href="index.html#section3">LANDLORDS</a></li>
        <li><a href="#section4">CONTACT</a></li>
      </ul>
</nav>

Links do not move to the index page or the desired section of the index page.

Thanks in advance.

Now i have

<section>
       <a name="section1"></a>
    </section>

    <section id="section2">

    </section>

    <section>
       <a name="section3"></a>
    </section>

    <section id="section4">

    </section>

and my navigation:

<nav>
      <ul>
        <li><a href="#section1">ABOUT</a></li>
        <li><a href="#section2">APARTMENTS</a></li>
        <li><a href="#section3">LANDLORDS</a></li>
        <li><a href="#section4">CONTACT</a></li>
      </ul>
</nav>

It still doesn't work

+4
source share
4 answers

Are you sure you placed the files in the same directory? I tested the code you provided and it works. However, you can try this (another way to provide id partitions):

<section>
    <a id="section1">
        CONTENT
    </a>
</section>

, :

<a href="different-page.html#section1">Section One</a>
+9

javascript , "event.preventDefault();"

bootstrap w3school, , . , .

+5

, Legacy Browser (IE8 ). firefox, chorm IE9. . .

anchor div id.

:

<a name="section1"></a>
<section>section content goes here </section>

<a name="section2"></a>
<section>section content goes here </section>

<a name="section3"></a>
<section>section content goes here </section>

<a name="section4"></a>
<section>section content goes here </section>

...

0
source

Source: https://habr.com/ru/post/1525597/


All Articles