You will need Javascript to do this.
(您将需要Javascript来执行此操作。)
Use window.close()
: (使用window.close()
:)
close();
Note: the current tab is implied.
(注意:隐含当前选项卡。)
This is equivalent: (这等效于:)
window.close();
or you can specify a different window.
(或者您可以指定其他窗口。)
So:
(所以:)
function close_window() {
if (confirm("Close Window?")) {
close();
}
}
with HTML:
(使用HTML:)
<a href="javascript:close_window();">close</a>
or:
(要么:)
<a href="#" onclick="close_window();return false;">close</a>
You return false
here to prevent the default behavior for the event.
(您在此处return false
以防止事件的默认行为。)
Otherwise the browser will attempt to go to that URL (which it obviously isn't). (否则,浏览器将尝试转到该URL(显然不是)。)
Now the options on the window.confirm()
dialog box will be OK and Cancel (not Yes and No).
(现在, window.confirm()
对话框上的选项将为“确定”和“取消”(不是“是”和“否”)。)
If you really want Yes and No you'll need to create some kind of modal Javascript dialog box. (如果您确实想要“是”和“否”,则需要创建某种模式的Javascript对话框。)
Note: there is browser-specific differences with the above.
(注意:上述内容与浏览器特定。)
If you opened the window with Javascript (via window.open()
) then you are allowed to close the window with javascript. (如果使用Javascript打开窗口(通过window.open()
),则可以使用javascript关闭窗口。)
Firefox disallows you from closing other windows. (Firefox不允许您关闭其他窗口。)
I believe IE will ask the user for confirmation. (我相信IE会要求用户确认。)
Other browsers may vary. (其他浏览器可能会有所不同。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…