简体   繁体   English

如何在单击按钮 HTML 代码上关闭浏览器?

[英]How do I close a browser on click button HTML code?

How do I close a browser window with HTML code?如何关闭带有 HTML 代码的浏览器窗口?

all browser compatibality所有浏览器兼容性

window.close(); window.close(); not working不工作

See the second reply below for a discussion on when the window can be closed:有关何时可以关闭窗口的讨论,请参阅下面的第二个回复:

window.close and self.close do not close the window in Chrome window.close 和 self.close 不会关闭 Chrome 中的窗口

I'm quoting the answer of this question我引用了这个问题的答案

Scripts are not allowed to close a window that a user opened.不允许脚本关闭用户打开的窗口。 This is considered a security risk.这被视为安全风险。 Though it isn't in any standard, all browser vendors follow this (Mozilla docs).尽管它不是任何标准,但所有浏览器供应商都遵循此(Mozilla 文档)。 If this happens in some browsers, it's a security bug that (ideally) gets patched very quickly.如果这种情况发生在某些浏览器中,那么这是一个安全漏洞,(理想情况下)会很快得到修补。

Use window.close() for close the window or tab in javascript

$(".close-btn").click(function(event) {
    window.close();
});

Try window.top.close();试试 window.top.close(); or window.close();或 window.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在按钮单击时关闭整个浏览器? - How to close entire browser on button click? 如何在React中渲染的按钮单击时关闭? - How do I close upon button click of a rendered component in react? 如何使用控制台中的代码关闭浏览器控制台 - How do I close the browser console with code in the console 如何防止fancybox关闭? 想要使用户单击“关闭”按钮,而不是在浏览器上的任何位置 - How can I prevent fancybox from closing? Want to make the user click the Close button instead of anywhere on the browser 当我单击 Javascript 中另一个按钮的内容时,如何关闭一个按钮内容 - How do i make one button content close when i click another button's content in Javascript 我想在单击关闭浏览器时调用 function...按钮关闭浏览器的元素? - i want call a function when click close browser ... element of button close browser? 如何在HTML提交按钮单击中添加到URL? - how do I add to the URL in an HTML submit button click? 单击按钮后,如何将干净的HTML复制到剪贴板? - How do I copy clean HTML to clipboard on button click? 每当我单击js中的按钮时,如何关闭最后打开的window - How do I close the last open window whenever I click the button in js 怎么办我点击 javascript 中的按钮触发此代码 - how to do i fire this code on click of a button in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM