Uncategorized

Time Out code, Timed Trigger to Auto redirect or Auto navigate to another page or URL

About Time Out codes are generally used in scenarios when you want to automate a trigger based on after a specific amount of time has...

About

Time Out codes are generally used in scenarios when you want to automate a trigger based on after a specific amount of time has passed. In this case, we are using the Time Out code to redirect a person to another Wix page or an external URL

Here are some common scenarios of when to trigger the Time Out code:

  • When the page loads

  • When a button is clicked

  • When a dataset is saved

  • After a query or filter has been executed

Good to Know #1

The Time

The code is written in milliseconds, therefore the number:

  • 5000 is equivalent to 5 seconds

  • 1000 is equivalent to 1 second

  • 60000 is equivalent to 1 minute

  • 3600000 is equivalent to 1 hour

Good to Know #2

The Code to redirect to another Wix page

On Page Load:

import wixLocation from 'wix-location';$w.onReady(function() {
 const millisecondsToDelay = 5000;    setTimeout(() => {
        wixLocation.to(`/join`);
    }, millisecondsToDelay);
});

On Button Click:

import wixLocation from 'wix-location';$w.onReady(function () {
    $w("#myElement").onClick((event) => {
 const millisecondsToDelay = 5000;        setTimeout(() => {
            wixLocation.to(`/join`);
        }, millisecondsToDelay);
    });
});
    

After Dataset Saved:

import wixLocation from 'wix-location';$w.onReady(function () {
    $w("#myElement").onAfterSave(() => {
 const millisecondsToDelay = 5000;        setTimeout(() => {
            wixLocation.to(`/join`);
        }, millisecondsToDelay);
    });
});
    

After Query is executed:

import wixLocation from 'wix-location';import wixData from 'wix-data';$w.onReady(function () {
    //
});// ... some other code that triggered the querywixData.query("myCollection")  .find()
  .then( () => {
 const millisecondsToDelay = 5000;        setTimeout(() => {
            wixLocation.to(`/join`);
        }, millisecondsToDelay);
  } )
  .catch( (err) => {
 let errorMsg = err;
  } );
 

After Filter is executed:

import wixLocation from 'wix-location';import wixData from 'wix-data';$w.onReady(function () {
    //
});// ... some other code that triggered the filter$w("#myDataset").setFilter( wixData.filter()
  .startsWith("lastName", "D")).then( () => {
  console.log("Dataset is now filtered");
 const millisecondsToDelay = 5000;        setTimeout(() => {
            wixLocation.to(`/join`);
        }, millisecondsToDelay);
} ).catch( (err) => {
  console.log(err);
} );

Good to Know #3

The Code to redirect to an external URL

On Page Load:

import wixLocation from 'wix-location';$w.onReady(function() { 
 const millisecondsToDelay = 5000; 
    setTimeout(() => {         
        wixLocation.to(`https://www.wix.com/marketplace/hire/web-design`);     }, millisecondsToDelay); 
});

On Button Click:

import wixLocation from 'wix-location';$w.onReady(function () {
    $w("#myElement").onClick((event) => {
 const millisecondsToDelay = 5000;        setTimeout(() => {
            wixLocation.to(`https://www.wix.com/marketplace/hire/web-design`);        }, millisecondsToDelay);
    });
});
    

After Dataset Saved:

import wixLocation from 'wix-location';$w.onReady(function () {
    $w("#myElement").onAfterSave(() => {
 const millisecondsToDelay = 5000;        setTimeout(() => {
            wixLocation.to(`https://www.wix.com/marketplace/hire/web-design`);        }, millisecondsToDelay);
    });
});
    

After Query is executed:

import wixLocation from 'wix-location';import wixData from 'wix-data';$w.onReady(function () {
    //
});// ... some other code that triggered the querywixData.query("myCollection")  .find()
  .then( () => {
 const millisecondsToDelay = 5000;        setTimeout(() => {
            wixLocation.to(`https://www.wix.com/marketplace/hire/web-design`);        }, millisecondsToDelay);
  } )
  .catch( (err) => {
 let errorMsg = err;
  } );
 

After Filter is executed:

import wixLocation from 'wix-location';import wixData from 'wix-data';$w.onReady(function () {
    //
});// ... some other code that triggered the filter$w("#myDataset").setFilter( wixData.filter()
  .startsWith("lastName", "D")).then( () => {
  console.log("Dataset is now filtered");
 const millisecondsToDelay = 5000;        setTimeout(() => {
            wixLocation.to(`https://www.wix.com/marketplace/hire/web-design`);        }, millisecondsToDelay);
} ).catch( (err) => {
  console.log(err);
} );

Author

by Code Queen

Corvid , Wix Design, Project Planning, Private Tutoring

Services world wide

Stuck on a project? Hire Code Queen, LLC!

Schedule a phone call or video call directly online. In a different time zone? No problem! Code Queen currently has clients around the world.

Share this post

Loading...