javascript 单击警报消息中的确定后如何关闭浏览器中的当前窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17567126/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 08:48:59  来源:igfitidea点击:

How to close the current window in browser after clicking ok in the alert message?

javascripthtmlalert

提问by Manik

based on some actions in a page , I want to give an alert message to the user (ie.. your resume has been uploaded.) like that and i want to close that window, when the user clicks okay in that alert box. I want to do this using alert method only instead of confirm method in javascript. why because alert method gives the only option "ok" where as confirm method gives " yes or no" .can anyone help me please.

基于页面中的某些操作,我想向用户发出警报消息(即..您的简历已上传。),当用户在该警报框中单击“确定”时,我想关闭该窗口。我只想使用警报方法而不是 javascript 中的确认方法来做到这一点。为什么因为警报方法给出了唯一的选项“确定”,而确认方法给出了“是或否”。请任何人帮助我。

回答by Laurent S.

Just put the statements one after each other :

只需将语句一个接一个地放置:

alert("ok");
window.close();

EDIT following Ankit's remark to OP : note that if you didn't open the window with Javascript yourself, you may not be authorized to close it depending on the browser.

按照 Ankit 对 OP 的评论进行编辑:请注意,如果您没有自己使用 Javascript 打开窗口,则根据浏览器的不同,您可能无权关闭它。