How To: Go To Page, Then Execute This Code/Interaction?

Similar to anchors, how can I have a button somewhere in my footer that once clicked would navigate to a particular page and then trigger a specific bit of interaction, say show a collapsed box or something like that? Is this possible yet?

Hay Omid,

Sure it is. But first, we need to keep in mind that we need to pass information between pages on navigation, something that is possible using one of 2 mechanisms - session storage , or a url parameter .

The navigation itself is done using the wix-location.to function.

Before the navigation store something in the sessions storage, or add a url parameter to the target page url.

On the target page, in the onReady handler, read from session storage or from the url parameter and trigger the interaction only if you have the marker in session storage or the url parameter.

Note - session storage exists for as long as the browser tab is open. You will need to clear it on the onReady event.
URL parameter exists only for the current navigation, but also if you go back in history using the browser back button.

Thanks Yoav!

Yoav,

Would you mind guiding me a little more here please? How can I figure out (where is the KB) for the queriy strings (I will use URL parameters) that would impact the interaction exactly? Is there a particular example I can learn from. I tried searching but could not find it. What should I put in the URL as the string and how would Wix know what it means and what to trigger, I am missing that bit, as I was not expecting that connection to data will be required for this purpose. Accordingly, would you also please clarify if this means the interaction/element in question on the target page HAS TO BE CONNECTED TO DATA?

My original need is related to a STATIC item and interaction to be triggered from ANY page when a permanent button on footer is clicked

> GO TO HOMEPAGE
> BASICALLY AUTOMATICALLY CLICK/TRIGGER THIS OTHER BUTTON ON HOMEPAGE (TARGET PAGE)
> THEN SHOW/EXPAND THIS SPECIFIC BOX AND SET OF OTHER ITEMS AS IF THE USER HAD 
MANUALLY PRESSED THE RELATED BUTTON ON THE HOMEPAGE/TARGET PAGE)

You do not need any connection to data for this. Url parameters are formally called a query, it had nothing to do with a database query.

  1. Create a url if the page with a parameter.
    Http://site.com/page?param=value

  2. On the in ready event look for the param.

$w.onReady(() => {
If(wixLocation.query.param === ‘value’)
// Do something
})

Gotcha. My bad. Too noob to easily figure this stuff out sometimes. still trying this crutch2clutch but not there yet :slight_smile:

Yoav

This is my attempt per your suggestion, assuming my URL triggering this is alexthedefender.com/?param=about

$w.onReady(() => {If(wixLocation.query.param === 'about');
  	$w('#aboutbox').show("flipin");
	$w('#aboutbox').expand();
	$w('#aboutbtn').hide("fadeout");
	$w('#resultsbtn').hide("fadeout");
	$w('#practicebtn').hide("fadeout");
	$w('#contactbtn').hide("fadeout");
	$w('#title').hide("fadeout");
	$w('#abtbtn2').show("floatin");
	$w('#resultsbtn2').show("floatin");
	$w('#practicebtn2').show("floatin");
	$w('#contactbtn2').show("floatin");
	$w("#resultsbtn2").enable();
	$w("#practicebtn2").enable();
	$w("#abtbtn2").disable();
	$w("#contactbtn2").enable();
})

However, upon inputting this I get the following errors, could you please guide me as to what I may be doing wrong?

wow. Major PEBKAC reporting for duty :slight_smile:

If did not work.
if did the trick.

Beautiful work mademoiselle. :clap: :+1: Houston Attorney | Alexander J. Houthuijzen, Attorney-at-Law

This actually ran into issues later. I am now trying it on another page and am having a hard time getting multiple url parameters to load alternative segments of the page and my default url also seems to be doing the parameter behavior anyway. Have a seprerate thread for it, but figure I may get an answer here on how to stack these correctly.

Question: I could not find it in documentation: How do I use wix-locataion.to with lightboxes? is this possible?

Hi Omid,
I tried using the code above to get two elements to hide/show on a target page. I linked a button on the homepage using this link: https://gvdagency.wixsite.com/realestategreece-cop/services?param=test
and then, on the target page i used the code below:

$w.onReady(() => { if (wixLocation.query.param === ‘test’);
$w(“#textshow”).show();
$w(“#texthide”).hide();
})

import wixLocation from ‘wix-location’;

I want to show a hiddenonload text with the id: “textshow” and hide a visible text with the id: “texthide”.

However, when the page https://gvdagency.wixsite.com/realestategreece-cop/services?param=test loads, nothing happens, the “textshow” text is still hidden and the “texthide” text is visible. I don’t get any errors in the code pannel.

Could you please help me on this?
Thank you

I published the site and now, when I click the button on the homepage the code works, however, when i navigate from the main menu to the page: https://gvdagency.wixsite.com/realestategreece-cop/services
the code still works as if i navigated from the button (“textshow” is visible and “texthide” is hidden).

Any thoughts on how I could get this to work please?