HTML按钮关闭窗口 [英] HTML Button Close Window
本文介绍了HTML按钮关闭窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个html按钮,我想单击时关闭当前窗口。我想我可以像下面那样设置onclick功能。我错过了什么?
I have an html button that I want to close the current window when clicked. I thought I could just set the onclick feature like I did below. Am I missing something?
<button type="button" onclick="javascript:window.close()">Discard</button>
推荐答案
当您在onclick属性中不需要指定是的。
When in the onclick attribute you do not need to specify is javascript.
<button type="button"
onclick="window.open('', '_self', ''); window.close();">Discard</button>
这应该这样做。为了关闭它,你的页面需要被脚本打开,因此window.open。这里有一篇文章详细解释了这一点: http:// www。 yournewdesigner.com/css-experiments/javascript-window-close-firefox.html
This should do it. In order to close it your page need to be opened by the script, hence the window.open. Here is an article explaining this in detail: http://www.yournewdesigner.com/css-experiments/javascript-window-close-firefox.html
这篇关于HTML按钮关闭窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文