Open Tab based on URL parameter

Is there a way to select a particular tab based on the URL parameter?

Hi Pete,

There’s no ready-made “open tab X from URL parameter” option - Bricksforge has no tabs element of its own and no tab action, so the tab itself stays the Bricks tabs element. But you can wire it up in the Node Editor with two nodes:

  1. Event: Document Events > On Page Load
  2. Action: Advanced > JavaScript, connected to that event

Code for the JavaScript node:

const i = parseInt(new URLSearchParams(location.search).get('tab'));
if (!isNaN(i)) document.querySelectorAll('.my-tabs .tab-title')[i]?.click();

Replace .my-tabs with the CSS class of your tabs element. ?tab=0 opens the first tab, ?tab=1 the second, and so on. Clicking the tab title is exactly what Bricks reacts to, so the panes and active states are handled for you.

Kind regards
Daniele

Thanks Daniele,
I have not used the Node Editor to date, this seems an ideal opportunity to learn a bit more. Also, your explanation is really great, straightforward and precise.
Regards
Pete