Reload or refreshing a page can be useful if, for example, you are using a form to edit a post and the form is on the post itself. Reloading a page is easy to do using some simple JavaScript. The JavaScript is as follows:
location.reload();
Using the Run JavaScript Action
The Run JavaScript action can be used to run the reload method. To do this:
- When editing your form, click the Actions icon at the top of the page. The Actions sidebar will open on the side of the page.
- Click the Add icon to add a new action.
- Select JavaScript from the Action pulldown.
- Is the JavaScript setting, enter
location.reload();
. - Click Save & Close.
- Publish your form.
Now when the form is submitted, the page will reload.
Note that reloading and redirecting a web page may prevent other JavaScript on the page from running, e.g. analytics events.
Using Conditional Logic
JavaScript can also be run using conditional logic. For example you could run JavaScript with a custom button is clicked. To do this:
- Click the Conditional Logic icon at the top of the layout editor. The Conditional Logic sidebar will open.
- Click the Add icon to add a new condition.
- When editing THEN, choose Form > Run JavaScript.
- Enter
location.reload();
. - Click Save & Close.
- Publish your form.
In the above example the page would be reloaded each time the custom button is clicked. Clicking the button would clear any data entered into the form at that point.
Bypassing The Browser Cache
Should you encounter an issue where the page content does not reload correctly, it may be due to the browser cache retrieving a cached version of the page. To address this, you can ensure a fresh reload by setting the forceGet
parameter to true
in the reload method, as demonstrated below:
location.reload(true);