How to kill firefox child process/tab from Java/C++

后端 未结 3 362
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 14:16

I have my application in Java which invokes a browser [IE or Firefox etc ] ..

Requirement is when my Java Application exits i have to kill all the web pages [Child p

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 14:47

    Good question.

    There are several solution.

    The first is the following. Run browser not directly but using script (shell for unix, bat file for windows) that will report you the process ID of the browser that it runs. Then use kill -9 PID on linux and taskkill on windows. This solution will require you writing scripts for different platform (at list for 2).

    But I have other suggestion. If the URL that you are opening in browser is yours (I mean you can add some javascript there) you can do the following. The URL that you are opening will create AJAX call to server. When you close your application you should say to server to send command to the browser to close it. At this moment javascript that is running into the browser will close its window. This is the most cross-platform solution.

    BTW I think that the server that is used by mentioned AJAX component may be your own application. And the signal that you send to the AJAX component is just connection error. Really, if your application is the server and you are closing it, the AJAX call will fail. This 100% means that the browser should be closed too.

提交回复
热议问题