Hi,
I would like to create a function where I click on an item on the home page, and the result will be to load a different page on the site, and then hide and element on the second page and show another element on the second page.
Any thoughts?
Thank you
Just use if current user logged in or set by user roles, then show or hide any element on that second page…
Thank you for your answer!
I am experiencing the following problem:
I would like when a user navigates from the homepage to the page “services”, from a button on the homepage linked to the “services” page, to show/hide some items and when he navigates to the page “services” from the main menu to just show the page as it is.
I used a parameter in the linked button ( https://gvdagency.wixsite.com/realestategreece-cop/services?param=test ), and then the following on the “services” page:
$w.onReady(() => { if (wixLocation.query.param === ‘test’);
$w(“#textshow”).show();
$w(“#texthide”).hide();
})
However, no matter if I navigate to the “services” page from the linked button or from the main menu, the code runs. Also I tried it yesterday and it worked (when I navigated from the menu the page stayed the same and when I navigated from the button the items showed/were hidden), without changing anything in the code panel.
Can you please help?
@enter
Hi George:
OK I have looked at your page and the code above. I have highlighted the error you are encountering below:
import wixLocation from 'wix-location';
$w.onReady(() => {if(wixLocation.query.param === 'test'); // <<< REMOVE THE ';'
$w("#textshow").show();
$w("#texthide").hide();
})
Basically whenever you use a semi-colon in javascript you effectively terminate the statement. Whenever you are writing a conditional statement in javascript it is good practise to use curly braces to define the block of statements that are ‘scoped’ to the conditional test. So instead of the previous code I propose you use the following syntax:
import wixLocation from 'wix-location';
$w.onReady(() => {
if(wixLocation.query.param === 'test')
{
// All statements inside of the curly braces will execute if the
// if() condition above is true.
// REFERENCE: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#Block_statement
$w("#textshow").show();
$w("#texthide").hide();
}
})
Cheers