0

I want to open a url in default browser like internet explorer 11, firefox but url should not open browser if default browser is edge or google chrome. Below code open the url in default browser, I want to restrict launch of browser if default browesr is edge or google chrome.

public class LaunchBrowser {
 public static void main(String args[])
  {
    String url = "http://www.google.com";
    String os = System.getProperty("os.name").toLowerCase();
    Runtime rt = Runtime.getRuntime();
    try{
          if (os.indexOf( "win" ) >= 0) {
          rt.exec( "rundll32 url.dll,FileProtocolHandler " + url);
       }
     catch(Exception e){
       return;
     }
   }
 }
Manish Pareek
  • 69
  • 1
  • 5
  • Your title and text are contradicting each other. Do you want to find out whats the default browser (thats what you as in the text) or do you want to launch a specific browser of your choice (thats what you ask in the title)? – MDK Oct 29 '20 at 12:18
  • hi! I have updated title for better understanding. – Manish Pareek Oct 30 '20 at 18:13
  • You can find out which browser is used using [this](https://stackoverflow.com/questions/15852885/method-returning-default-browser-as-a-string) approach and then let the program decide whether it want to proceed or not. – MDK Oct 30 '20 at 19:04
  • I checked you link but not working for me on win 10 Pro. getDefaultBrowser() always return "Iexplore" as string. No matter what default browser is. – Manish Pareek Nov 02 '20 at 12:22

0 Answers0