Hi everyone,
I’m currently creating my “one time pop-up”. However, I cannot figure out how to detect a click (inside the OnReday{}) and then just print “Done” to test it. Here is my code :
import {local} from ‘wix-storage’;
import wixWindow from “wix-window”;
$w.onReady(function () {
//TODO: write your page related code here...
if(!local.getItem(“firstTimePopupShown8”)) {
// open popup
wixWindow.openLightbox(“Cookies”);
// local.setItem(“firstTimePopupShown6”, “yes”);
function button1_click() {
//Add your code for this event here:
local.setItem(“firstTimePopupShown6”, “yes”);
console.log(“done”);
}
}
});
Thanks for your answer 
Instead of looking for a solution in the onReady, have you tried any onClick event inside the LightBox itself, like a button?
Thanks for your answer. Yes I’ve tried in the Lightbox itself and it doesn’t work. I think it’s because the button has a link, when I remove the link, then it works but the link is essential… Any idea ?
Could you show a screen shot of the lightbox and then explain how you want it to behave?
Yes no problem. It is simply a cookie message bar. For now (the code is below), the bar is displayed only when the user comes for the first time (whether he accepts or not). But I would like to display the message for every session until the user accepts the terms. So the only thing I want to add is the action " local.setItem(“firstTime1”, “yes”); " (last action in the code) but only when the user clicks on the button.
If you can’t read the screenshot, here is the code:
import {local} from ‘wix-storage’;
import wixWindow from “wix-window”;
$w.onReady(function () {
//TODO: write your page related code here…
if(local.getItem(“firstTime1”)!==“yes”) {
// open popup
wixWindow.openLightbox(“Cookies”);
// set flag for future visits
local.setItem(“firstTime1”, “yes”);
}
});
Ah, complicance with EU-cookie regulation. Well, you have a button there (“J’accepte”). In its property window, you choose its onClick event. Wix will then generate something like
function btnJaccepte.click (assuming you named it btnJaccepte, it could also be button3 or something)
at the bottom of you code.
There, in that function, you put the code for the local storag, the local.setItem.
I’ve already tried this and it doesn’t work because the button is already linked…
To a page to close a window…
I want to help you, but you are kind of sparse with giving me information. What window? This lightbox? Please be specific,
I mean the button is there to close the light box and it already has a function and I see that I can’t use the onclick() event if the button is linked…
Hi,
Having both link and onClick is not a good practice, as you define two different behaviours for a button.
Roi
Ah ok, so do you know how can I have both a link and an event on the button click ?
Can you describe which event and link ?
Roi
I have lightbox with a button which is linked to close the lightbox. But I also want to add this action when the button is clicked:
local.setItem(“firstTime1”, “yes”);
Hi again,
First of all link the button to “none” (to cancel the linking)
Next, create an onClick event to the button.
This is a sample of how the code should look:
import {local} from 'wix-storage';
export function buttonInLightbox_click(event, $w) {
local.setItem("key", "value")
wixWindow.lightbox.close();
}
For more information of Lightbox code
Good luck!
Roi
Great thanks ! It’s exactly what I needed. But can you tell me how should I use the onclick event inside OnReady() as it doesn’t work with “export function” ?
The function should not be in the scope of onReady
Roi
Ok no problem I’m going to try it and i will give you a feedback, thank you.