I made a similar post to this a few weeks ago but hadn’t done much of my own testing and ultimately got nowhere. I’ve been trying to figure this out since, but I just can’t do it so I’m making another post with, I think, a clearer premise.
I’m trying to create a button as a 'sub to unlock" feature, where by a user clicks a button, opening an link in a new tab to my YouTube channel, and when they return to the original tab, the button has hidden, revealing the text underneath.
I’ve made a test page for this ( https://www.liambetham.com/test-two ). The page contains only a button and the text underneath.
My First Idea is this:
Set the button to hide using an onClick event, something like this:
export function button_click(event) {
let fadeOptions = {
"duration":500,
"delay":1000
};
$w("#button65").hide("fade", fadeOptions);
}
And then set the button to also open the link to subscribe in a new tab, with the addition of this:
$w.onReady(function () {
$w("#button65").link = "https://www.youtube.com";
$w("#button65").target = "_blank";
}
However, with this setup the button hides, but the link doesn’t open. I believe this is as .link is supposed to go under “$w.onReady(function)”, rather than an onClick event and the onClick event which is required to hide the button overrides the “$w.onReady(function)” code.
The alternative, which does work with an onClick event, is “wixLocation.to”, but this lacks the ability to open a link in a new tab, therefore directing users away from the original content which is supposed to be ‘unlocked’.
My second idea is this:
Set the button to open the YouTube link in another tab, and in the original tab open a copy of the page where the button doesn’t exist to block the content. For example, open https://www.youtube.com in a new tab, and take the current tab to my home page; https://www.liambetham.com.
I tried this with this code:
$w.onReady(function () {
$w("#button65").link = "https://www.youtube.com";
$w("#button65").target = "_blank";
$w("#button65").link = "https://www.liambetham.com";
});
However, this just opens my home page in a new tab and I’m really not sure why.
If someone could either point out any error(s) in my code, tell me another solution entirely, or come up with a fix for the overall goal itself that would be really appreciate.
Thanks,
Liam