javascript 单击“确定”警报按钮时刷新页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21247674/
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
Refresh the page when the 'OK' alert button is clicked
提问by user3213765
I have an alert script that shows to users who don't have an underscore between the numbers they wrote in the input of the form (e.g 888_1132).
我有一个警报脚本,可以向在表单输入中写入的数字之间没有下划线的用户显示(例如 888_1132)。
Since I can't remove the 'OK' button from the alert, I want the page to be refreshed when the 'OK' button is clicked.
由于我无法从警报中删除“确定”按钮,因此我希望在单击“确定”按钮时刷新页面。
function myFunction()
{
alert("Click 'OK' to refresh this page");
}
Can I do that with the alert button? Thanks in advance.
我可以用警报按钮做到这一点吗?提前致谢。
回答by Scary Wombat
As the script will block until the OK is pressed, then simply add location.reload();
below the alert
由于脚本将阻塞,直到按下 OK,然后只需location.reload();
在警报下方添加
function myFunction()
{
alert("Click 'OK' and the page will be refreshed");
location.reload();
}
回答by Deryck
window.location.reload(true);
Add that RIGHT after your alert()
在你之后添加 alert()
Including true
will ensure the page is fully reloaded from the server and not from local cache. If you want to use cache, leave blank or use false
包括true
将确保页面完全从服务器而不是从本地缓存重新加载。如果要使用缓存,请留空或使用false