英文:
Window sometimes retuns a blank page after reloading
问题
当我从父窗口打开子窗口时,我希望在保存后子窗口重新加载,但有时子窗口会返回一个空白页面。
我想要独立于父窗口操作重新加载子窗口。
子窗口只在Chrome中返回空白。
代码应该在Chrome和Firefox中都能正常工作。
我用来重新加载窗口的代码:
setTimeout(() => location.reload(true), 2000);
英文:
When I open a child window from a parent window, I want it to reload after saving but sometimes the child window returns a blank page.
I want to reload the child window independent of the parent window action.
child window returns blank only in Chrome.
The code should work in both Chrome and firefox.
My code that reloads the window:
setTimeout(() => location.reload(true), 2000);
答案1
得分: 1
抱歉,我无法将此代码放入一个代码段中,因为我需要多个文件,但我测试过它可以工作。
index.html:
<html>
<head></head>
<body>
父窗口
<button>打开子窗口</button>
<script>
var button = document.querySelector("button"); //获取按钮
button.onclick = function() {
window.open("child_window.html","_blank", "width=500,height=500,left=100,top=100,toolbar=0,status=0"); //打开子窗口
}
</script>
</body>
</html>
child_window.html:
<html>
<head>
</head>
<body>
子窗口
<button>重新加载</button>
<script>
var button = document.querySelector("button"); //获取按钮
button.onclick = function(){
//2秒后重新加载页面
document.write("页面将在2秒后重新加载...");
setTimeout(()=>{
if(navigator.userAgent.toLowerCase().includes("firefox")){
window.location.reload(true);
}else{
window.location.reload();
}
}, 2000);
}
</script>
</body>
</html>
我不知道你的问题的原因是什么,因为这段代码在Chrome中可以工作。如果有问题,请告诉我。
英文:
Sorry, I could not put this code into a snippet because I needed multiple files, but I tested it and it worked.
index.html:
<html>
<head></head>
<body>
Parent Window
<button>Open Child Window</button>
<script>
var button = document.querySelector("button"); //Get the button
button.onclick = function() {
window.open("child_window.html","_blank", "width=500,height=500,left=100,top=100,toolbar=0,status=0"); //Open the child window
}
</script>
</body>
</html>
child_window.html:
<html>
<head>
</head>
<body>
Child Window
<button>Reload</button>
<script>
var button = document.querySelector("button"); //Get the button
button.onclick = function(){
//Reload the page after 2 seconds
document.write("The page will reload in 2 seconds...");
setTimeout(()=>{
if(navigator.userAgent.toLowerCase().includes("firefox")){
window.location.reload(true);
}else{
window.location.reload();
}
}, 2000);
}
</script>
</body>
</html>
I don't know what the cause of your problem was, since this code works in Chrome. Let me know if it works.
答案2
得分: 0
不要使用Firebase的forceGet
参数,因为它是实验性的,不被广泛支持。
如果需要强制重新加载并绕过缓存,请传递
true
。
如果不必要的话,避免使用它。
英文:
Do not use Firefox's forceGet
parameter as it is experimental and not widely supported.
> Pass true
to force a reload bypassing the cache.
Avoid using it if it's unnecessary.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论