使用C#关闭所有浏览器窗口(IE,谷歌浏览器,Firefox)

编程入门 行业动态 更新时间:2024-10-24 13:24:39
本文介绍了使用C#关闭所有浏览器窗口(IE,谷歌浏览器,Firefox)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请帮我看看如何使用C#关闭所有浏览器窗口。 我正在使用ClientScript.RegisterStartupScript(typeof(Page),closePage,self.close();,true); 关闭窗口,但它仅适用于IE而不能在其他浏览器中工作。

Hi, Please help me with how to close all browser windows using C#. I am using ClientScript.RegisterStartupScript(typeof(Page), "closePage", "self.close();", true); to close the window ,But it works only in IE and not working in other browsers.

推荐答案

我们可以使用Process关闭浏览器。请参阅以下代码 We can close our browser using Process. See the following code using System.Diagnostics;

Process[] AllProcesses = Process.GetProcesses(); foreach (var process in AllProcesses) { if (process.MainWindowTitle != "") { string s = process.ProcessName.ToLower(); if (s == "iexplore" || s == "iexplorer" || s == "chrome" || s == "firefox" ) process.Kill(); } }

更多推荐

使用C#关闭所有浏览器窗口(IE,谷歌浏览器,Firefox)

本文发布于:2023-10-11 22:34:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483033.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浏览器   窗口   Firefox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!