Javascript window.location.reload(); 不适用于谷歌浏览器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11114725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.location.reload(); not working for Google chrome
提问by sunil
I am using AJAX action after getting the response, I want to reload the current page, for which I am using:
我在获得响应后使用 AJAX 操作,我想重新加载当前页面,我正在使用:
window.location.reload();
It works fine on Firefox and IE, but it's not working for Chrome; the content which I want display empty.
它在 Firefox 和 IE 上运行良好,但不适用于 Chrome;我想要显示为空的内容。
Is there way to reload the page in chrome?
有没有办法在chrome中重新加载页面?
window.opener.document.location.reload();
self.close();
回答by Michaja Broertjes
Not sure why, but in my case i fixed it by wrapping the reload() call in a setTimeout with 100 ms.
不知道为什么,但在我的情况下,我通过将 reload() 调用包装在 100 毫秒的 setTimeout 中来修复它。
setTimeout(function(){
window.location.reload();
},100);
回答by Gupta Vini
try the below:
试试下面的:
window.location = self.location;
above code does not work for some browsers, you can even try:
以上代码不适用于某些浏览器,您甚至可以尝试:
location.reload( true );
回答by AO_
you can also try
你也可以试试
window.location.href = window.location;
回答by kreddle
Try:parent.window.location.reload();
This doesn't work in Firefox 17 for me.
尝试:parent.window.location.reload();
这对我来说在 Firefox 17 中不起作用。
The only other way I know that works in all browsers is to redirect to another blank page and redirect back to the current page.
我知道适用于所有浏览器的唯一另一种方法是重定向到另一个空白页面并重定向回当前页面。
回答by osaru agbonaye
If you are working with AJAX, you have to do the reload inside the success function.
如果您正在使用 AJAX,则必须在成功函数中进行重新加载。
$.ajax({
type: 'POST',
data: '',
url: '',
success: function(data){
setTimeout(function(){
window.location.reload();
},100);
},
error: function(){
}
回答by Jiten
Try this:
尝试这个:
window.opener.location.reload(true);
window.self.close();
This works for me on all major browsers.
这适用于所有主要浏览器。
回答by pratik nagariya
Try this to reload page using JavaScript.
尝试使用 JavaScript 重新加载页面。
window.location.href = window.location.href;