Advertisement
Guest User

Untitled

a guest
May 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public void showURLInBrowser(String url) {
  2. String operatingsystem = System.getProperty("os.name").toLowerCase();
  3. Runtime rt = Runtime.getRuntime();
  4. try {
  5. if (operatingsystem.indexOf("win") >= 0) {
  6. String[] cmd = new String[4];
  7. cmd[0] = "cmd.exe";
  8. cmd[1] = "/C";
  9. cmd[2] = "start";
  10. // cmd[3] = url; így kezeli 1 form változónál többet is!
  11. cmd[3] = url.replace("&", "\"&\"");
  12. rt.exec(cmd);
  13. } else if (operatingsystem.indexOf("mac") >= 0) {
  14. rt.exec("open " + url);
  15. } else {
  16. //prioritized 'guess' of users' preference
  17. String[] browsers = {"epiphany", "firefox", "mozilla", "konqueror", "netscape", "opera", "links", "lynx"};
  18. StringBuffer cmd = new StringBuffer();
  19. for (int i = 0; i < browsers.length; i++) {
  20. cmd.append((i == 0 ? "" : " || ") + browsers[i] + " \"" + url + "\" ");
  21. }
  22.  
  23. rt.exec(new String[]{"sh", "-c", cmd.toString()});
  24. }
  25. } catch (Exception e) {
  26. printFramework("The system failed to invoke your default web browser while attempting to access: " + url);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement