Jump to content

Button which links to random page on site

Go to solution Solved by creedon,

Recommended Posts

Hi, not sure if this is even possible. But I would like to have a button (or a hyperlinked word in a text block) which will link the user to a random page from a pre-selected list of pages on my site.

The button is the one on the home page named 'Sunrise me!' (or the words 'Surprise me!' in the text block) and I would like it to randomly select one of my folio projects.
/architecture/bower-studio
/architecture/bonbeach-trail
/graphic-design/commbank
/photography/landscape
etc...

Just a fun little thing I want to add, but if it's not possible or too complicated, not a a big deal.

Thanks

Kind regards,
Ashwin

https://ashwingunawardana.squarespace.com/
Password: password

Link to comment

I was unable to get it to work. I put the code onto the home page settings > advanced > page header code injection.
For "const selector" I put the block id of the button
For "const urlPrefix' I tried '/' and '/collection_name'
And for "const strings" I tried both 'collection-name/page-name' and '/page-name'

I'm guessing I'm putting in the wrong values for one or more of these things.
I want the list to have pages from different collections. So /architecture/bower-studio and /graphic-design/commbank and so on

Link to comment
  • Solution
Quote

I've added it to a new page which is locked.

The selector needs to be...

        const selector = '#block-yui_3_17_2_1_1688984615330_1727 a';

This targets the block and the link in the block so the URL can be replaced.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.