Check current url with script (content lock)

Highlighted
New Member
10 0 0

Hi gurus,

Anyone can assist to take a look at the below? Cant get it work, everytime it shows false. I checked assigned "value" and is same with the URL i indicated, but doesnt work in formula. Im trying to simple lock some features on the page with a custom url. So when custom URL trigger the formula "True" - i will open content. Features are not sensitive info or some sort of it, so simple trick with URL will do.

<div id="pre-order">
 {% assign value = '<script>document.getElementById("pre-order").innerHTML = window.location.href;</script>' %}        {% if value == 'https://mysite.com/products/test-product#allow' %} 
true
{% else %}
false
{% endif %}

<div> 

 

Any help will be appreciate, or maybe there is another concept.

0 Likes
Shopify Partner
918 17 159

Hi Tommy,

You are mixing client side evaluated code with server side evaluated code. Liquid runs server side. Javascript runs client side. You cannot assign some Javascript to a Liquid variable, expect that Javascript to run and get the result in that Liquid variable.

Best wishes!

I turn coffee in to code - since 1998
0 Likes
New Member
10 0 0

Understand. Thx for reply, still learning liquid.

If someone need

I solved my problem by creating custom Pre Order page,  apply Dynamic content script and also shopify out of stock notifier. Now content can be locked to pre order only. Its not sort of high security, but will work for me (i have a plan B just in case also).

Dynamic scipt here

https://jennamolby.com/how-to-display-dynamic-content-on-a-page-using-url-parameters/

Shopify out of stock notification here

https://www.google.com/url?sa=t&source=web&rct=j&url=https://help.shopify.com/en/themes/customizatio...

 

Browsing normal page, which is locked for order, only pre order form, sample here

https://topkidz.sg/collections/new-arrivals/products/2nos-awesome-handmade-hair-clip-ribbon-purple-c...

Unlocked page (url with extra params), which allow customers to make a purchase, here

https://topkidz.sg/collections/new-arrivals/products/2nos-awesome-handmade-hair-clip-ribbon-purple-c...

 

Now there is still a message shows how many stock available, but im working on it removal, beeketing hide it dont know where, waiting their support to help.

0 Likes
New Member
53 0 0

Hi Tommy,

 

This is a nice trick, I will check when I get time, thanks for posting :)

 

Best,

Gajendra.

support@storefreelancer.com | Top Rated Upworker | Shopify Developer and Designer | Theme Customization
0 Likes