I would like you to reach a certain page only via a preceding disclaimer.If you do not come from the disclaimer, you should be redirected to a start page. Unfortunately I always get to the start page with my script. What is wrong?
Disclaimer: https://www.mysite. com/disclaimer
Safesite: https://www.mysite. com/safesite
Starsite: https://www.mysite. com/start
import wixWindow from ‘wix-window’;
$w.onReady(function() {
if wixWindow.referrer === "https://www.mysite. com/disclaimer" {
[wixLocation.to(“https://www.mysite.]( wixLocation.to(“https://www.mysite.) com/safesite”);
}else if wixWindow.referrer === "https://www.mysite. com/disclaimer?lang=en” {
[wixLocation.to("https://www.mysite.]( wixLocation.to(“https://www.mysite.) com/safesite?lang=en”);
}
else {
[wixLocation.to("https://www.mysite.]( wixLocation.to(“https://www.mysite.) com/start”);
}
});
import wixWindow from ‘wix-window’;
$w.onReady(function() {
if (wixWindow.referrer === "https://www.mysite. com/disclaimer") {
wixLocation.to("https://www.mysite. com/safesite");
}
else if (wixWindow.referrer === "https://www.mysite. com/disclaimer?lang=en")
{
wixLocation.to("https://www.mysite. com/safesite?lang=en");
}
else {
wixLocation.to("https://www.mysite. com/start");
}
});
We need to add Open Bracket ’ (’ and Close Bracket ‘)’ near IF condition
Example :
Let name = “Akon”;
if ( name === “Akon” ) {
console.log(“Play Smack That Song”);
} else {
console.log(“don’t Play Songs”);
}
okay!
I am searching for some time already, for the descriptions of logical operators and comparisons. So far I only know the following
&& = And
|| = Or
=== = equal
!== = unequal.
But I miss smaller/larger NAND/NOR and others.
Does your problem Solved ?
I can only test again tomorrow at 07:00 UTC
I could test earlier. Unfortunately it does not work. I always come to the start page, but never to the safe page.
I have tested another variant, but also without success.
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;
$w.onReady(function() {
if (wixWindow.referrer !== “https://www.mysite. com/disclaimer” && wixWindow.referrer !== “https://www.mysite. com/disclaimer?lang=en”) {
wixLocation.to(“https://www.mysite. com/start”);
}
});
My code should work.
In which page you written my code.
Need to write in both disclaimer pages.
Not in home page or site
Thanks
Kottravai
The website is multilingual. The code is therefore on both sides. I have the code on the safesite, because I want to test here, if somebody came over a deeplink to the site.
Now I try to set a variable as a marker on the disclaimer page and read it out on the safe page. Maybe this works.
I tried it now with a variable but unfortunately it does not work either. Obviously “discl” remains on “YES” after it was set once.
new code:
Disclaimersite:
import {local} from ‘wix-storage’;
local.setItem(“discl”, “YES”);
Safesite:
import wixLocation from ‘wix-location’;
import {local} from ‘wix-storage’;
const discl = local.getItem(‘discl’);
$w.onReady(function() {
if (discl !== “YES”) {
wixLocation.to(“https://mysite .com/startpage”);
}
});
After switching from “local” to “session” it works. What is the difference between “local” and “session”, why does “local” seem to be permanent?
import {session} from ‘wix-storage’;
session.setItem(“discl”, “YES”);
Safesite:
import wixLocation from ‘wix-location’;
import {session} from ‘wix-storage’;
const discl = session.getItem(‘discl’);
$w.onReady(function() {
if (discl !== “YES”) {
session.setItem(“discl”, “NO”);
wixLocation.to(“https://www.mysite .com/startpage”);
}
});
I tested that on my site and it works. BUT the “onready” event is after the page is loaded and displayed. SO what happens is that the page is displayed and then it immediatly disaperears to show the ‘startpage’. I looked to another event but could not find one related to something like ‘startloadingpage’ or 'beforedisplay" . Any idea on that?
It works for me too, but not in a multilingual environment. I have solved this now by setting a marker “discl” and querying it. See 2 posts above.