Post by E@gle2313 » Mon Feb 19, 2018 9:15 pm

Hello,

I'm on OC 3.0.2.0 and i've te following problem:

I have a couple if anchors on the left side of my page and on the right side i have my text and where the anchors point to.
But when i click on the anchor

link:
<p><a href="#C4">Jump to Chapter 4</a></p>

anchor:
<h2 id="C4">Chapter 4</h2>

When i do this then i go to my homepage.

Could somebody help me with this problem, i have found some posts but none are working for me.

kind regards,

Ben

Newbie

Posts

Joined
Thu Nov 23, 2017 10:15 pm

Post by uksitebuilder » Mon Feb 19, 2018 9:45 pm

It will be because of base href tag in your head section. Anchors will not work unless you specify full URL

e.g. https://www.yoursite.com/some-seo-url#some-anchor

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by E@gle2313 » Mon Feb 19, 2018 10:00 pm

Owh okay.

Is there a simple way to get my current url ?

kind regards,

Ben

Newbie

Posts

Joined
Thu Nov 23, 2017 10:15 pm

Post by uksitebuilder » Tue Feb 20, 2018 12:04 am

In your herf, put the full URL to the page followed by #C4

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by E@gle2313 » Tue Feb 20, 2018 4:01 pm

thnx, but i mean is there a way to get the current URL.
Because i need it on every productpage.

kind regards,

Ben

Newbie

Posts

Joined
Thu Nov 23, 2017 10:15 pm

Post by uksitebuilder » Tue Feb 20, 2018 4:07 pm

In that case, probably an easier method would be to use Javascript/jquery in the product twig file

So you link and anchor would be:

link:
<p><a href="javascript:void(0);" class="C4">Jump to Chapter 4</a></p>

anchor:
<h2 id="C4">Chapter 4</h2>

Code: Select all

<script>
$(".C4").click(function() {
    $('html, body').animate({
        scrollTop: $("#C4").offset().top
    }, 2000);
});
</script>
Don’t forget to clear your caches (admin - Dashboard - Click cog top-right)

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by E@gle2313 » Tue Feb 20, 2018 9:07 pm

thnx, i got it working :)

Newbie

Posts

Joined
Thu Nov 23, 2017 10:15 pm
Who is online

Users browsing this forum: ravikumar22 and 79 guests