Using wix velo or another method, can someone help me create a script that will redirect a user if the page they are attempting to access is not loading within an iframe.
It looks like you’re looking for professional support with modifying your site. Try https://www.wix.com/marketplace for paid support.
I figured it out. Here is the code for anyone who needs it in the future. My specific use case is checking if a page is loading within an iframe on my subdomain. If it doesn’t redirect.
import wixWindowFrontend from 'wix-window-frontend';
import wixLocation from 'wix-location';
$w.onReady(function () {
// get last page
let referrer = wixWindowFrontend.referrer;
console.log(referrer)
//ensure page contains portal URL
let result = referrer.includes("portal.ctfeval.com");
console.log(result)
//logic
if (result === false) {
// The page is not loaded within an iframe on CTF Portal
console.log("Page is not loaded within an iframe on the protal. Redirecting...");
wixLocation.to("https://www.ctfeval.com/access-denied");
} else {
// The page is loaded within an iframe
console.log("Page is loaded within an iframe on CTF Portal.");
}
});
1 Like