开发者

Getting the user's default browser in Java

I want to know how to get the location of the user's default Internet browser in Java. How can I get this? I would prefer it as a URI to the browser's 开发者_如何学编程executable file. Must work cross-platform.


The safest thing you can do is something like this:

if (Desktop.isDesktopSupported()) 
{
  Desktop.getDesktop().browse("your url here");
}

more info on the Desktop class (mail, print, edit, etc) here


You should be using the Desktop class for this. This is the cross platform API that will invoke the default browser.


I would prefer it as a URI to the browser's executable file.

From your comments, I assume that you want this information when the user visits your site with his / her web browser. If so, the answer is that the information is not available unless you can convince the user to install a trusted browser plugin / addon or run a trusted applet.

The reason is that it would be a security breach for an untrusted web page to be able to get this information. It reveals information about the user's personal preferences, and potentially makes it easier for hackers to target the user's browser and compromise his / her machine.

The best you can do is look at the HTTP request's UserAgent header. This may be inaccurate, but that is the user's perogative.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜