window.location.href = window.location.href和window.location.reload()之间的区别 [英] Difference between window.location.href=window.location.href and window.location.reload()

查看:195
本文介绍了window.location.href = window.location.href和window.location.reload()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript之间有什么区别

What is the difference between JavaScript's

window.location.href = window.location.href

window.location.reload()

函数?

推荐答案

如果我没记错的话, window.location.reload()使用POST数据重新加载当前页面,而 window.location.href = window.location.href 不包含POST数据。

If I remember correctly, window.location.reload() reloads the current page with POST data, while window.location.href=window.location.href does not include the POST data.

正如@ W3Max在下面的评论中所述, window.location.href = window.location.href 如果URL中有锚(#),则不会重新加载页面 - 您必须使用 window.location.reload()在这种情况下。

As noted by @W3Max in the comments below, window.location.href=window.location.href will not reload the page if there's an anchor (#) in the URL - You must use window.location.reload() in this case.

另外,如下面的@Mic所示,窗口。 location.reload()接受一个额外的参数 skipCache 以便使用 window.location.reload(true)浏览器将跳过缓存并重新加载页面从服务器。 window.location.reload(false)将执行相反操作,并尽可能从缓存加载页面。

Also, as noted by @Mic below, window.location.reload() takes an additional argument skipCache so that with using window.location.reload(true) the browser will skip the cache and reload the page from the server. window.location.reload(false) will do the opposite, and load the page from cache if possible.

这篇关于window.location.href = window.location.href和window.location.reload()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆