JavaScript Location.reload()
method provides means to reload the page at current URL.
JavaScript Location.reload()
方法提供了在当前URL重新加载页面的方法。
The syntax is the following:
语法如下:
object.reload(forcedReload);
, where forceReload
is an optional parameter.
object.reload(forcedReload);
,其中forceReload
是可选参数。
To simply reload the page, you can input window.location
as object.
要简单地重新加载页面,您可以输入window.location
作为对象。
Optional parameters force reload
is a boolean value, which if set to:
可选参数force reload
是一个布尔值,如果设置为:
True
reloads the page from the server (e.g. does not store the data cached by the browser):
True
从服务器重新加载页面(例如不存储浏览器缓存的数据):
window.location.reload(true);
False
reloads the page using the version of the page cached by the browser.
False
使用浏览器缓存的页面版本重新加载页面。
window.location.reload(false);
False
is the default parameter, so if left blank, object.reload()
reloads the page using the broswer’s cached data, i.e. is identical to using the method as object.reload(false)
.
False
是默认参数,因此,如果留空, object.reload()
将使用浏览器的缓存数据重新加载页面,即与将方法用作object.reload(false)
。
To create the effect of browser-provided “Refresh”-option, you may want to create HTML-button and do either of the following:
要创建浏览器提供的“刷新”选项的效果,您可能需要创建HTML按钮并执行以下任一操作:
attach
Location.reload()
to the HTML button-markup, like this:将
Location.reload()
附加到HTML按钮标记,如下所示:
<input type="button" value="Refresh Button" onClick="window.location.reload()">
- assign on-click event to the button with the function that uses the method, where the button looks similar to 使用使用方法的函数将点击事件分配给按钮,其中按钮的外观类似于
<button type="button" onClick="reloadThePage()">Refresh!</button>
<script>
function reloadThePage(){
window.location.reload();
}
</script>
例: (Example:)
// Reload the current resources from the server
window.location.reload(true);
// Reload the current resources from the browser's cache
window.location.reload();
This will reload the page at the current URL from the server.
这将从服务器以当前URL重新加载页面。
更多信息: (More Information:)
翻译自: https://www.freecodecamp.org/news/location-reload-method-how-to-reload-a-page-in-javascript/