How can I retrieve a hash string from the current URL in Shopify?

How can I retrieve a hash string from the current URL in Shopify?

yy0410
Shopify Partner
5 1 1

Hello everyone,

 

I'm new to shopify.

I have an issue related to hash.

I'd like to get a hash string in current page.

I tried it, but it didn't work

 

Codes I wrote is below

 

・a page before transition

In this, page, I added an original hash to href of an a tag.

For example . the url will be /pages/lookbook#abc if collection.metafields.custom.title is abc.

                  {% assign hash = collection.metafields.custom.title | handleize %}
                  {% assign url = pages["lookbook"].url | append: "#" | append: hash %}


                  <a href="{{ url }}" class="page-collection__card">
                    <div class="page-collection__box">
... </div> </a>

・a page after transition

I wrote this codes cause I want to confirm what url I can see.

The result was "/pages/lookbook". This didn't include "#abc"

{{ page.url }}

 

However, url of display showed "http://~/pages/lookbook#abc".

In addition, I wrote blew a code and the resulted "#abc".

console.log(location.hash)

 

I need someone to tell me the reason.

Replies 0 (0)