How to use a different default browser for different websites

Why?

Some websites that you use regularly will work better in a certain browser. Whether it be age-old corporate intranets that work better in Internet Explorer or modern web apps that work better in Chrome.

Concept

The concept is pretty simple. You create something that launches browsers based on the criteria you specify and set it as your default browser. It is launched whenever you click a http/https link and it, in turn, launches the desired browser.

The New Default Browser

I chose to write this as a Batch script as this seemed quickest. My Batch knowledge is pretty non-existent so it’s probably not very good. It’d be better written in something like C# as you wouldn’t get the very brief cmd popup every time you click a link. Here’s the code:

  1. @setlocal enableextensions enabledelayedexpansion
  2. @echo off
  3. set tehurl=%1
  4. set res=false
  5.  
  6. if not x%tehurl://rpm.newrelic.com=%==x%tehurl% set res=true
  7. if not x%tehurl://docs.google.com=%==x%tehurl% set res=true
  8. if not x%tehurl://drive.google.com=%==x%tehurl% set res=true
  9.  
  10. if "%res%"=="true" (
  11. start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "%1"
  12. ) else (
  13. start "" "C:\Program Files (x86)\Opera\opera.exe" "%1"
  14. )
  15.  

You’ll see a list of domain names and two browser launchers – Chrome and Opera. The concept is that the listed URLs launch in Chrome and everything else in Opera. The URLs are specified in the format //domain.com so as to match http(s)://domain.com/something.

Changing The Default Browser in Windows

This requires some registry hacking. This article summarizes the process well. Firstly you need to create a class which contains the details of your new browser. Classes are found in the Windows registry at HKEY_CURRENT_USER\Software\Classes. Hopefully you can find the class for your current default browser to copy however it’s as simple as creating a new REG_SZ key called something like HKEY_CURRENT_USER\Software\Classes\Phil.Protocol\shell\open\command with a value of “path to your browser” “%1”. The %1 is important such that the clicked URL is passed through to your script. Screenshot below:

Screenshot of registry configuration for a browser class

Screenshot of registry configuration for a browser class

Once a class is created, you must associate it with the http and https protocols. You do this by setting the class name into the Progid key at HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http and HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https respectively. Screenshot below:

Screenshot of registry configuration for default browser

Screenshot of registry configuration for default browser

Testing

You should immediately see that when you click a link, for example, in an e-mail it’ll launch the desired browser.

Leave a Reply

Your email address will not be published. Required fields are marked *