doka1101
doka1101

Reputation: 41

Java - opening URL in internet explorer using java Desktop

I want to know if there is a way to open a webpage specifically in internet explorer using the java Desktop utility. My company uses both firefox and IE, but the url that needs to be open, is only compatible in IE. So, my java class needs to open that url in IE no matter what the default browser is.

Thanks for your help.

Upvotes: 4

Views: 8951

Answers (3)

AnkUser
AnkUser

Reputation: 5531

This might be late to answer the question, But still I will try to add my 2 cents. The question asked is "How to open URL in internet explorer using java Desktop" The below line of code mentioned in previous answer is correct but it will open in IE only if path is set to it. If there is not path set it will not work and throw error Runtime.getRuntime().exec("iexplore.exe www.stackoverflow.com");

To Force Java open Webpae in IE below is the line of code worked for me even though my default browser is Edge and path for IE is "not" set.

Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore.exe https://carelink.minimed.eu/");

Thanks

Upvotes: 1

ecoray
ecoray

Reputation: 1

try this:

//e.g. myURL=www.google.ch
public void openBrowser(String myURL) {

    //open default OS browser
    URI myURI;
    try {
        myURI = new URI(myURL);
        Desktop my = Desktop.getDesktop();
        if (!Desktop.isDesktopSupported()) {
            System.out.println("[WARNING] NOT SUPPORTED");
        }
        my.browse(myURI);
    } catch (URISyntaxException | IOException e1) {
        e1.printStackTrace();
    }
}

Upvotes: -1

Tudor
Tudor

Reputation: 62459

Sure:

Runtime.getRuntime().exec("iexplore.exe www.stackoverflow.com");

Upvotes: 8

Related Questions