Hi. How would I launch the default html browser from my program under both windows and linux?
Cheers.
Hi. How would I launch the default html browser from my program under both windows and linux?
Cheers.
For linux, you can use system("firefox") to open firefox. Lynx might also be a linux command you'd want to look into.
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
Code:Windows DOS console: STARTUPINFO siStartupInfo; PROCESS_INFORMATION piProcessInfo; memset(&siStartupInfo, 0, sizeof(siStartupInfo)); memset(&piProcessInfo, 0, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo); if(CreateProcess("firefox", // Application name 0, // Application arguments 0, 0, FALSE, CREATE_DEFAULT_ERROR_MODE, 0, 0, // Working directory &siStartupInfo, &piProcessInfo) == FALSE) // Could not start application -> call 'GetLastError()' Windows GUI: ShellExecute(hwnd,"open","firefox",NULL,NULL,SW_SHOWNORMAL);
Thanks guys. But both answers are restricted to the operating system and secondly it assumes firefox is installed.... What I would like is something like what you see in many programs when you click the help button.... it spawns the default browser and opens the programs help html file... So let me backtrace....
1. How can I launch the system's default browser?
Secondary less important question... which I doubt it can be answered as "default programs" are going to be restricted to the system...
2. Can this be done in a way independently of operating system....
Cheers
To be honest, I don't know, but as I said before, you can use lynx (in Linux) to go to basically any website on the internet, the only problem being that it's not really a browser.
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
There is no cross platform answer to this problem. You will need to find a solution for each platform and then determine a way to use the correct method depending on which platform you are running on.
If you check the windows board you'll find how to launch the default browser.
For Linux, you'll have to figure out what the default browser is. I don't know how to do this other than looking for an entry in the files $HOME/.mailcap and /etc/mailcap for the MIME type text/html, but I'm assuming that this is not what you really want, as it's intended for use within mail programs, not for stand-alone graphical viewing.
I'm guessing that both KDE and Gnome (and many other window managers with file browsers) have their own file to application association databases (ususally based on file extension). The answer may be quite complex indeed.
It is possible that on Windows, you can simply spawn off the URL in question to the command processor (via the system() call or some such) and the default browser will get invoked. I know that you can type a URL into the "Run" dialog on the XP desktop and the browser will be started.
I hope this helps.
Insert obnoxious but pithy remark here