Results 1 to 3 of 3
  1. #1
    ktden is offline Member
    Join Date
    Mar 2013
    Posts
    10
    Rep Power
    0

    Default open a url with firefox

    i have this code that opens a url with the default browser...

    <code>
    public void hyperlinkUpdate(HyperlinkEvent e){
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {

    try {

    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
    try {

    desktop.browse(new URI(e.getURL().toString()));
    }catch(URISyntaxException URI){System.err.println("error");}
    } catch(IOException ioe) {System.err.println("error");
    }
    }
    }
    </code>

    i would like to choose the browser where the url gets open...(for example... firefox or chrome)
    any idea?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: open a url with firefox

    If the program takes a URL String as an arg on the command line when it is executed, you could use the Runtime and Process classes to execute the program with the URL as its arguments.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    ktden is offline Member
    Join Date
    Mar 2013
    Posts
    10
    Rep Power
    0

    Default Re: open a url with firefox

    tx NORM,
    that new code do what i want:
    Java Code:
       public void hyperlinkUpdate(HyperlinkEvent e){
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                              
                    //METODO UNIVERSAL PARA ABRIR EL NAVEGADOR POR DEFECTO
    
     /*       java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
            try {
             try {
    
             desktop.browse(new URI(e.getURL().toString()));
              }catch(URISyntaxException URI){System.err.println("error");}
                    } catch(IOException ioe) {System.err.println("error");
          } */
                  //METODO PARTICULAR PARA ABRIR LINK CON FIREFOX  
                 try{    
    Process p = Runtime.getRuntime().exec("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"+" "+e.getURL().toString());  
                }catch(Exception e1){}
        }
      }

Similar Threads

  1. JTabbedPane look like FireFox
    By definder1986 in forum AWT / Swing
    Replies: 0
    Last Post: 06-22-2011, 02:58 PM
  2. Get URL from Firefox
    By simpleboy in forum New To Java
    Replies: 2
    Last Post: 04-17-2009, 01:49 PM
  3. Issue jsp with FireFox
    By dimuthunsj in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 10-10-2008, 11:08 AM
  4. IE and Firefox
    By Ed in forum Advanced Java
    Replies: 1
    Last Post: 06-15-2007, 04:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •