Content on your SharePoint page gets updated every time it refreshes or reloads. This happens when you first open the page on your browser or every time you manually refresh it.
If you have data on your SharePoint page that needs to be updated in real time, you may want to refresh your page automatically after a certain amount of time. This article will demonstrate how to implement the Javascript code that can automatically refresh your page after a certain period.
Here is how it will look like:
TABLE OF CONTENTS
Prerequisites
- You must have the latest version of ShortPoint SPFx installed on your SharePoint environment.
- You must be a ShortPoint Designer with an active license.
Step-by-step Tutorial
Follow the steps below to learn how to add a Javascript code that will automatically refresh your page:
Step 1: Edit the ShortPoint Web Part
Go to the SharePoint page you want to use and click Edit:
Click the ShortPoint tag:
Select the pencil icon:
Step 2: Insert the Code Design Element
Click the plus icon:
Use the search bar to look for Code and select it:
Step 3. Copy the JavaScript code
Copy the Jave Script Code below:
setTimeout( function() { window.location.reload() }, seconds(2) // <= only change this line, possible values are the following // seconds(number) // minutes(number) // hours(number) // days(number) // example: minutes(15) will make the browser refresh every 15 minutes ) /** * do not touch beyond this point * utility methods */ function seconds(digit) { return digit * 1000; } function minutes(digit) { return seconds(digit) * 60; } function hours(digit) { return minutes(digit) * 60; } function days(digit) { return hours(digit) * 24; }
Step 4: Paste the copied code
Paste the code in the Javascript field:
Change the seconds(2) value according to your preference:
NOTEYou can also replace seconds(number) with minutes(number), hours(number), days(number). For example, minutes(15).
Step 5: Disable Sandbox Mode
Navigate to the Design tab:
Disable Sandbox Mode:
Once done, click the green check mark:
Step 6: Save
Click Save to apply all your changes:
That's it! Now, your page will automatically refresh after the time you set.
Related articles: