How to Make a Script Run After X Amount of Time
Adding scripts gives your site extra functionality. When you add a script at page level, you can delay the firing of scripts after X amount of time using our Events, Actions, and Targets feature. Here’s how.
- In the Page Builder, click on Page in the top toolbar, then click on Custom Scripts.
- Click the Page tab, then click Add Page Script. Give your script a name (this is important because it allows your script to be targeted by Actions and Events).
- Add a description, and switch the script runs on page load toggle to Off.
- Next, choose the script position. If you are unsure where to put it, choose Body.
- Paste the code of your script into the box, and click Save.
Your script will be added, and a small red indicator will remind you that you need to republish your page(s) before you see the changes.
Next, we’ll add an Action at the page level to make the script fun after a certain amount of time.
- In the Menu Toolbar, click Actions.
- In the Elements Properties Panel, select Add New Action.
- Set up a new action with the following settings:
Event > Time > On time passed after page load
Action > Script > Run target script > 5 seconds
Target > Choose your script from the dropdown list
4. Click Done.
Now when you publish this page, your script will run 5 seconds after the page has loaded.