How to reload a page only once using JS
Question
Application Type
Reactive

I am using location.reload() in JavaScript but its causing page refresh infinity. I want to page refresh for only once. How to achieve this.

Hi Manjeet,

How exactly are you using the location.reload()? Normally this should only refresh the page once, so I'm thinking that your code might be being called repeatedly. Please check to make sure that you are not using the location.reload() in the On Initialize/Ready/Render events, because that would cause it to trigger itself after the reload.

Kind regards,
Jeroen

Hi Jeroen,

Thankyou for your response. I am using as this :

"

if(""" + EncodeJavaScript(Session.ZeroQuantity) + """=='True')
{
location.reload()
}
"

once the condition is true, its executing infinte but I want the page to refresh only once.

Where are you using this JavaScript, is it triggered by an event (e.g. On Ready, On Render, On Initialize) or by an action (e.g. a button being pressed)?
To prevent the page from being reloaded multiple times, you'll either need to prevent this JavaScript block from being called multiple times or set the ZeroQuantity variable to false when refreshing the page so the expression evaluates to false and the reload is not triggered again.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.