# Reload or Refresh

**URL:** <https://forums.knack.com/t/reload-or-refresh/9212>\
**Category:** API & Custom Code\
**Created:** [August 28, 2019, 5:20am UTC](https://forums.knack.com/t/reload-or-refresh/9212 "2019-08-28T05:20:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartinCraw46088](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@MartinCraw46088](https://forums.knack.com/u/MartinCraw46088)\
**Post date:** [August 28, 2019, 5:20am UTC](https://forums.knack.com/t/reload-or-refresh/9212/1 "2019-08-28T05:20:48Z")

</div>

I have an import function that works great, however I can't seem to find where I should add code to refresh the page. I've tried several places in my code, however none seem to work.

&nbsp;

Thanks

&nbsp;

---

<div class="post-metadata">

**Author:** ![ConorPower39695](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@ConorPower39695](https://forums.knack.com/u/ConorPower39695)\
**Post date:** [December 3, 2020, 4:26pm UTC](https://forums.knack.com/t/reload-or-refresh/9212/2 "2020-12-03T16:26:13Z")

</div>

Hi 367978297211  
  
Thank you for the "location.hash = location.hash + "#" " code.&nbsp;

I've been searching far and wide for code that would enable me to refresh the same scene that a form is located on. Reloading the whole page was causing an issue, as it was forcing users to log in again. And it caused an even bigger issue where we have an app embedded in another app.

This works perfectly, as it refreshes the whole scene, and as a result also applies the Page Rules again for that scene. My code snippet below that displays an alert, and refreshes the scene after the delay specified:

$(document).on('knack-record-update.view\_2855', function(event, view, data) {  
  
setTimeout(function () { location.hash = location.hash + "#"; }, 12000);  
  
alert("Please wait while we fetch the Invoice from Autoline. Click 'OK' & this page will refresh in a few moments...");

Knack.showSpinner();  
  
});

Thank you!

---

<div class="post-metadata">

**Author:** ![DeanAnders47112](https://avatars.discourse-cdn.com/v4/letter/d/8e7dd6/32.png) [@DeanAnders47112](https://forums.knack.com/u/DeanAnders47112)\
**Post date:** [October 19, 2019, 3:33am UTC](https://forums.knack.com/t/reload-or-refresh/9212/3 "2019-10-19T03:33:27Z")

</div>

Hi Martin, you may need to look at finding the correct javascript trigger, but here is what we use in the API& Code section in the builder under Javascript

&nbsp;

// does a quick refresh on the store add line item order screen  
$(document).on('knack-record-create.view\_901', function(event, view, record) {  
location.hash = location.hash + "#"  
});

&nbsp;

You'll need to find your view number (instead of view\_901) and you'll need to work out with your input what is the trigger. In my example we are tracking knack-record-create

We find the location.hash = location.hash + "#" works really well as it doesn't refresh the entire page and does its refresh very quickly.

&nbsp;

I hope this helps a little!

Cheers

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![PeterBurto32327](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@PeterBurto32327](https://forums.knack.com/u/PeterBurto32327)\
**Post date:** [November 4, 2021, 4:20pm UTC](https://forums.knack.com/t/reload-or-refresh/9212/4 "2021-11-04T16:20:48Z")

</div>

Is it possible to use this code to automatically refresh a page when a user lands on it? What I need is to ensure that my app users are getting the most up-to-date version of the app, therefore I need to force a page refresh as soon as they log in. Would your code work and are there any changes for my specific use case?

---

<div class="post-metadata">

**Author:** ![KnackPros](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/knackpros/32/807_2.png) [@KnackPros](https://forums.knack.com/u/KnackPros)\
**Post date:** [January 11, 2022, 10:22am UTC](https://forums.knack.com/t/reload-or-refresh/9212/5 "2022-01-11T10:22:01Z")

</div>

Hi @PeterBurto32327

You can use `location.hash` or `location.reload()` but you may have an infinite loop because the page reloading will probably trigger it again to reload. So instead, I would use one of the methods provided by the global `Knack` object.

For example:  
`Knack.views[view.key].model.fetch()`  
`Knack.views[view.key].render()`

The method depends on the view type (for example, table, details, etc).

I’d be happy to learn more about your use-case. [You can schedule a time here.](https://calendly.com/knackpros)

Thanks,  
Ian  
[Knack Pros](https://knackpros.com)
