OnClick - open lightbox & open external URL in separate window

Hello!
I’m in WiX EDITOR

THIS is what I am trying to do:

Click button —> lightbox opens in current win + Open external URL in a separate window

  • I have the button link setting set to NONE
  • “exit-survey” is the lightbox NAME, and
  • I have the following code:

Screenshot 2023-08-18 at 9.09.53 PM

I am only ever able to do ONE thing:
I am successfully opening the lightbox, and before I got the lightbox working, I had the external URL opening… but the external URL no longer opens.

Any thoughts are most appreciated.
Cynthia-

P.S. NOTICE on the 2nd line of code: “import wixLocation…”
the line is dimmed, like it’s a comment. Can someone tell me why it is not bright like the other lines of code? I’m wondering if this is indicating something.

Hi @web,

The reason your wixLocation import statement isn’t showing ‘brighter’ than the wixWindow is because you aren’t declaring the statement anywhere in your function. You are only declaring wixWindow.

I believe you are looking for something like this:

import wixLocationFrontend from 'wix-location-frontend';
import wixWindowFrontend from 'wix-window-frontend';

$w.onReady(function () {
    
//Replace 'buttonId' with your button ID
    $w("#buttonId").onClick(function () {

        wixLocationFrontend.to("https://www.whiteoakpastures.com/verified12", "_blank");

        wixWindowFrontend.openLightbox('exit-survey');
    });
});

I guess it’s more of a curiosity…why are you opening a link to a new tab, as well as opening the lightbox? The new tab will take snap the user to that new tab and they’d have to click back to see the opened lightbox. Just curious more than anything? :slight_smile:

Anyway, that code should do you.

1 Like

Thank you so much, Robert… and I understood what you said completely… and thank you also for the info on the “dimmed” declaration line.

I will try out your code and let you know the outcome. REALLY appreciate it.


As for the seemingly-illogical behavior I am attempting to execute: The button is taking ppl to a 3rd party site where I am an affiliate. I have no control over anything in the external site and absolutely NO metrics whatsoever re: the actions of the ppl I send. I am flying blind and it is virtually impossible to tweak my marketing based on visitor behavior - and we’re sending 2-3k ppl to the site a month.

We want the lightbox to be there when they come back to our site/tab - even if they’re just going to close the tab - on the chance that even just a FEW ppl will be willing to answer 2 quick questions: did you buy? and If not, why - check all that apply:"

We’re not expecting everyone, or even a LOT of ppl to bother with the lightbox, but if we can just get a little insight, it could help us dramatically.

Thank you again… I’ll be trying your suggesting shortly. : -)

REPORTING BACK on your code suggestion, Robert…

It’s ignoring the TARGET parameter _blank and loading the external URL in the current window. I CAN see it open the lightbox for a split sec. before the entire content is replaced.

I tried swapping out the order - openlightbox first, then open external URL second - with no luck. It still replaces the current window.

Then, I tried moving the OpenLightbox command to within a buttonName_onClick function, for the heck of it. No luck.

Every way I try it, the LOCATION command is ignoring the TARGET parameter.

Here’s what I have

import wixLocationFrontend from ‘wix-location-frontend’;
import wixWindowFrontend from ‘wix-window-frontend’;

$w.onReady(function () {

$w("#buttDealsShop").onClick(function () {

  wixWindowFrontend.openLightbox('exit-survey');
  wixLocationFrontend.to("https://www.whiteoakpastures.com/verified12", "_blank");

});

});

Any thoughts?

NEW DEVELOPMENT on URL not opening in new window (ignoring _blank property):

All of a sudden it is showing an error - screenshot below. I looked up wixWindowFrontend and I am not seeing a TARGET property listed as an option.

Not sure what it’s referring to in the error: type “NavOptions”

I had a url opening in a separate window at one point, but it was ignoring the lightbox line. Still unable to get BOTH events to trigger: open lightbox in THIS window and external URL in a new window.

Any ideas?

Screenshot of error:

Thank you kindly!!!

Hi @web are you able to private message me? I would like to propose helping you further - it’s kind of hard to go back and forward with code without seeing your setup. Let’s take it offline and come back here with the solution once we’re done. How does that sound?

You’re so kind… thank you. Sure. I am new to the forum… let me look around for the DM link. BRB

I am assuming you are talking about messaging here on WiX. Do you mean like on WhatsApp? I am not finding a DM area or link. I’m open to whatever and am grateful.

I have tried a bunch of different approaches to no avail. I am actually a programmer from a LONG time ago, but changed careers at one point and am new to Velo. I understand most of it but am unfamiliar with the language.