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

Updated: Dec 10, 2020


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 query

wixData.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 query

wixData.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


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.


Online Booking: Discovery Session

Contact Form: Send project details

101 views0 comments

disclaimer

a quick note about our website content

Our free and premium content is non-exclusive, meaning you are not the only one with access to the content. You can customize our content to fit your end product. Redistribution of our content is strictly prohibited. This means you cannot make our content available to others as-is, stand-alone products or stock products in ANY LANGUAGE, regardless if you offer our content for free or not.