简体   繁体   中英

How to refresh a page once automatically right after it loads completely without changing or adding a string in the URL?

I created a script that looks for a particular class and once found appends a div to it. In order for this to work the page needs to be refreshed once without changing the url in the address bar, its like simulating the act of actually hitting the refresh button on the browser. Almost all answers I see here in Stack Overflow requires a string to be attached in the end of the url for the one time refresh to work. Is there actually a way to automatically refresh once after the page loads without changing the url in the address bar?

Have you tried location.reload();

Furthermore, you can use the localStorage property to store whether you have reloaded the page once so you don't reload forever.

https://www.w3schools.com/jsref/prop_win_localstorage.asp

将其与true location.reload(true)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM