window.open() opens IE, how do I open the default browser (ie opera or firefox) Do I need to use an ActiveX control
Thanks for your help
Andy
window.open() opens IE, how do I open the default browser (ie opera or firefox) Do I need to use an ActiveX control
Thanks for your help
Andy
Launching a page in the default browser
Koray Samsun
Biju S Melayil
sorry try this
var shell = new ActiveXObject("WScript.Shell");
shell.Run("http://www.google.com");
Karrar
The default value of "HKEY_CLASSES_ROOT\.html" will give you the browser reference.
From that, look up the default value of "HKEY_CLASSES_ROOT\<browser reference>\shell\open\command"
That will give you the EXE which you can run via Shell.execute. You thenl need to strip it down to the EXE and pass the parameters.
I've coded it for you below:
var browserEXE, browserParameters;
var oShell = new ActiveXObject("WScript.Shell");
findBrowser();
openBrowser("www.microsoft.com");
function findBrowser() {
var browserClass = oShell.RegRead("HKCR\\.html\\");
var browserShell = oShell.RegRead("HKCR\\" + browserClass + "\\shell\\open\\command\\");
var exeSplit = browserShell.toLowerCase().indexOf(".exe") + 4;
browserEXE = browserShell.substring(0, exeSplit);
browserParameters = browserShell.substring(exeSplit);
}
function openBrowser(url) {
System.Shell.execute(browserEXE, browserParameters.replace("%1", url));
}
ykgreene
This does not seem to work on Vista.
I installed firefox and set it as the default browser but the
htmlfile\shell\open\command was still related to internet explorer.
Did MS changed the file association mechanism in Vista>
Regards.
Jason D. Camp
As per my code above, you need to get the default value from "HKCR\.Html". This is the application class associated with .HTML files. If you look that up in HKCR, you'll have the default application path.
To change the file association, just Right Click on an HTML file and select Open With\Choose Default Program...
Bill Foust
Tom's way was much shorter because I don't actually need to find out what the default browser is, just launch it. Worked a treat.
Thanks again,
Andy
mumle
I've come a long way since then
toniolie, to launch a web page in the default browser you should just use System.Shell.execute("http://someurl.com");
Jonathan Abbott's method will allow you to find the exe of the default browser, but performing the execute method on a URL launches the default browser anyway.
Andy
jv_getmore
Andy,
Is there a way to know if an specific extension is associated to a particular application
In windows XP I used to go through the registry in order to ontain that information, but in Windows Vista it they changes the association to be bu user. I could have special code to do the same in Vista but I was looking for a way to do it programatically without having to check the registry, I searched un der the Shell32 API and I was not ablt to find anything.
I know that ShellExecuteEx() returns an error if the file extension is not associated, but I would like to know whether the extension is associated or not before trying to execute it.
Regards.