调用window.close()如何不出现确认窗口?

在IE中,新的IE进程调用window.close()会跳出确认对话框,从其他窗口打开的则不会。以往通过HTML HELP的ActiveX组件使新窗口关闭不跳出对话框的方法,在IE5.5及以上版本因安全考虑被禁止,文中还提及有更简单办法。
部署运行你感兴趣的模型镜像

当在IE中调用window.close()时,若当前IE是一个新的instance,即是一个new的IE进程,则IE会跳出一个确认对话框;若当前IE窗口是从其它IE窗口打开的,则不跳出对话框。

要使新的IE窗口在关闭时不跳出确认对话框,以往的做法是调用HTML HELP的ActiveX组件的功能,如:

<object id=closeWindow classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Close"></object>
<a href="javascript:document.all.closeWindow.Click()">关闭窗口</a>

出于安全性的考虑,这个办法在IE5.5及以上的版本中已经禁止了。

其实还有个最简单的办法:

<a href="javascript:window.opener=null;window.close()">关闭窗口</a>

呵呵,太简单了,为什么以前少有人试呢?

呵呵,太简单了,为什么以前少有人试呢?

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

在 C++ 中使用 SFML 调用 `window.close()` 时出现断开问题,可能涉及网络连接、资源释放等多方面因素。以下是一些可能的解决办法: ### 网络连接方面 若程序中存在网络连接(如 TCP 或 UDP 套接字),在关闭窗口前需确保网络连接正确关闭,避免出现断开问题。示例代码如下: ```cpp #include <SFML/Network.hpp> #include <SFML/Graphics.hpp> int main() { sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window"); sf::TcpSocket socket; if (socket.connect("127.0.0.1", 53000) != sf::Socket::Done) { return -1; } sf::Event event; while (window.isOpen()) { while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { // 关闭套接字 socket.disconnect(); window.close(); } } window.clear(); window.display(); } return 0; } ``` ### 多线程方面 若程序采用多线程,关闭窗口时要确保所有线程都已正确停止,避免资源泄漏和断开问题。可以使用互斥锁和条件变量来同步线程。示例代码如下: ```cpp #include <SFML/Graphics.hpp> #include <thread> #include <mutex> #include <condition_variable> std::mutex mtx; std::condition_variable cv; bool stopThread = false; void workerThread() { std::unique_lock<std::mutex> lock(mtx); cv.wait(lock, []{ return stopThread; }); // 线程结束前的清理工作 } int main() { sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window"); std::thread t(workerThread); sf::Event event; while (window.isOpen()) { while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { { std::lock_guard<std::mutex> lock(mtx); stopThread = true; } cv.notify_one(); t.join(); window.close(); } } window.clear(); window.display(); } return 0; } ``` ### 资源管理方面 确保在关闭窗口前释放所有动态分配的资源,如内存、文件句柄等。示例代码如下: ```cpp #include <SFML/Graphics.hpp> #include <vector> int main() { sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window"); std::vector<int*> dynamicMemory; for (int i = 0; i < 10; ++i) { dynamicMemory.push_back(new int(i)); } sf::Event event; while (window.isOpen()) { while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { for (auto ptr : dynamicMemory) { delete ptr; } window.close(); } } window.clear(); window.display(); } return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值