Close browser from java code using specific url ad

2019-09-22 09:25发布

1) I want to close specific browser tab using url address from my java code. As it is a client server applicaiton. I want to close browser tab using url address from my client application

The server side will have a jar that will communicate with client request and take the url from client and close the browser running in the server machine according the url address.

2) I want to close my firefox or chrome browser from my java code also. I don't want to kill process but shut down browser normally.

**I need this solution for ubuntu os.

Hope for your response.

2条回答
霸刀☆藐视天下
2楼-- · 2019-09-22 09:49

I am using following code to filter on the basis of login user. There you have to change the condition accordingly.

WebContext webContext = WebContextFactory.get();
Collection<ScriptSession> ss = webContext.getAllScriptSessions();
        for (ScriptSession s : ss) {
            if (s.getAttribute("uname")!=null && s.getAttribute("uname").equals(to)) {
                Util util = new Util(s);
                ScriptBuffer sc= new ScriptBuffer();
                sc.appendScript("window.close()");
                util.addScript(sc);
            }
        }
查看更多
ら.Afraid
3楼-- · 2019-09-22 09:57

You have to call a javascript to close the client's browser from your javascode. This is called reverse Ajax. You can achieve by using DWR framework. This a powerful API which help you to call Java from Javascipt and vice versa.

By using this you can filter clients browser that are onto a specific URL.

And this solution is not a OS specific it will work fine for every OS platform.

查看更多
登录 后发表回答