I have a dynamic page. I want to hide it if a person directly pastes the url of the page. However it will only show when it is redirected from a page. Is this possible to implement??
Same issue i faced.
can we shift wp site into wix? like below site
@mayukhsroy , I guess you can use wix-storage ( https://www.wix.com/corvid/reference/wix-storage.html ) (the session option), to store a permission once the user clicked your redirecting button.
Then, once a user gets to the page with the limited access, get the permission variable from the browser cache (session.getItem). If you don’t get the stored variable (which means the user never clicked your button, redirect this user to another page (using wix-location).
Technically you’d still be able to access it if you navigated directly to the URL afterwards. You’d have to either clear the cookie before you leave the page or else redirect away from the page if a certain hash or query isn’t met.
Yes. and an alternative (a little bit more “dirty”) way to do the same (instead of using wix-storage), is to put a transparent element on the header. To set it as hidden by default, and then on button click make it show (but it will be in fact invisible to human eye because it’s transparent).
Then on the target page, add the following code:
import wixLocation from 'wix-location';
$w.onReady(function () {
$w('#elementX').hidden ? wixLocation.to('somepage.com') : $w('#elementX').hide();
})
@jonatandor35 I didn’t get this… Can you elaborate this a little bit.
@mayukhsroy about the first option or the second one?
@jonatandor35 2nd one…
@mayukhsroy OK.
So, we’ll take advantage of the fact that the header is shown on all pages (it won’t work if you set the layout to “hide header”).
You can put a small box on the header and change its opacity to 0%. Make this box hidden by default.
Then on the first page where you have the redirection button, put the following code.
import wixLocation from ‘wix-location’;
$w.onReady(function () {
$w("#myRedirctionButton").onClick((event) =>{
$w("#myTransparentElement").show();
wixLocation.to("/myDynamicPagePath");
})
})
/* NOTES:
1. instead of "myRedirctionButton" use your button property Id;
2. instead of "myTransparentElement" use your transparent element property Id;
3. instead of "myDynamicPagePath" use your target page path;
*/
On the target page, use the following code:
import wixLocation from 'wix-location';
$w.onReady(function () {
$w('#myTransparentElement").hidden ? wixLocation.to("/noPermissionPagePath") : $w('# myTransparentElement").hide();
})
/* NOTES:
1. instead of "myTransparentElement" use your transparent element property Id;
2. instead of noPermissionPagePath, use the url path to a page where you show a message "You don't have a permission to watch this page");*/
By the way, I would rather use the first option (with wix-storage), as it’s cleaner.
@jonatandor35 Is the Wix storage option complicated?
@mayukhsroy no. It’s pretty simple. You can read it here: https://www.wix.com/corvid/reference/wix-storage.html
and don’t forget to clear the data from your cache once after the target page has loaded and permission has been set, as David said.
Just read this… So i need to use session from wix storage. Will just clearing the session data do the job.
You now what, I’ll put the code here:
import {session} from 'wix-storage';
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#myRedirctionButton").onClick((event) =>{
session.setItem("permission", "approved");
wixLocation.to("/myDynamicPagePath");
})
})
second page:
import {session} from 'wix-storage';
import wixLocation from 'wix-location';
$w.onReady(function () {
session.getItem("permission") === "approved" ? session.removeItem("permission"):
wixLocation.to("/myNoPermissionPagePath");
})
P.S edited as there were some typos.
Thanks mate. … I will try this and what about deleting cache
Also cancel the button link on the editor. All the functionality should be in the code.
PAY ATTENTION to the changes I’ve made in the code above.
@mayukhsroy the cache removing is in the code above :
session.removeItem("permission")
@jonatandor35 I already had a code there on first page. Just added your code. I hope its fine
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import {session} from 'wix-storage';
export function button2_click(event, $w) {
let emailid = $w('#input1').value;
let passkey = $w('#input2').value;
wixData.query("MemberList")
.eq('emailId', emailid)
.eq('password', passkey)
.find()
.then((results) => {
console.log(results);
if (results.items.length > 0) {
session.setItem("permission", "approved");
wixLocation.to(`/quizmain/${results.items[0]._id}`);
}
if (results.items.length === 0) {
$w('#text13').show();
}
})
.catch((err) => {
console.log("err", err);
});
}
So I am redirected to the page where you told me to write your 2nd page code.
Now what will be my Nopermissionpage path? - the one I am redirected to. What will be wix location?
Cant understand this part
import {session} from 'wix-storage';
import wixLocation from 'wix-location';
$w.onReady(function () {
session.getItem("permission") === "approved" ? session.removeItem("permission"):
wixLocation.to("/myNoPermissionPagePath");
)}
Can I add a button on this page which will delete the cache? or act as a logout button
I modified this a little bit. Is it correct??
import {session} from 'wix-storage';
import wixLocation from 'wix-location';
$w.onReady(function () {
session.getItem("permission") === "approved" ? session.removeItem("permission"):
wixLocation.to("/mainquiz");
})
export function button3_click(event) {
//Add your code for this event here:
session.removeItem("permission")
wixLocation.to("/mainquiz");
}
It’s up to you. You can create a page with a ‘no permission’ notification and redirect to there, or logout the user. Whatever you like.