位置重新加载方法:如何在JavaScript中重新加载页面

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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值