Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void showURLInBrowser(String url) {
- String operatingsystem = System.getProperty("os.name").toLowerCase();
- Runtime rt = Runtime.getRuntime();
- try {
- if (operatingsystem.indexOf("win") >= 0) {
- String[] cmd = new String[4];
- cmd[0] = "cmd.exe";
- cmd[1] = "/C";
- cmd[2] = "start";
- // cmd[3] = url; így kezeli 1 form változónál többet is!
- cmd[3] = url.replace("&", "\"&\"");
- rt.exec(cmd);
- } else if (operatingsystem.indexOf("mac") >= 0) {
- rt.exec("open " + url);
- } else {
- //prioritized 'guess' of users' preference
- String[] browsers = {"epiphany", "firefox", "mozilla", "konqueror", "netscape", "opera", "links", "lynx"};
- StringBuffer cmd = new StringBuffer();
- for (int i = 0; i < browsers.length; i++) {
- cmd.append((i == 0 ? "" : " || ") + browsers[i] + " \"" + url + "\" ");
- }
- rt.exec(new String[]{"sh", "-c", cmd.toString()});
- }
- } catch (Exception e) {
- printFramework("The system failed to invoke your default web browser while attempting to access: " + url);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement