spawn default html browser

This is a discussion on spawn default html browser within the C Programming forums, part of the General Programming Boards category; Hi. How would I launch the default html browser from my program under both windows and linux? Cheers....

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    28

    spawn default html browser

    Hi. How would I launch the default html browser from my program under both windows and linux?

    Cheers.

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    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

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    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);

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    28
    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

  5. #5
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    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

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    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.

  7. #7
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open default browser and send an HTTP request (POST Method)
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 09-03-2005, 01:31 AM
  2. Getting Default Browser and Running It
    By Driver in forum Windows Programming
    Replies: 4
    Last Post: 10-22-2004, 02:08 PM
  3. default browser and multiple users
    By Waldo2k2 in forum Tech Board
    Replies: 6
    Last Post: 10-05-2003, 12:03 PM
  4. Opening the default browser with a specified URL
    By sundeeptuteja in forum C++ Programming
    Replies: 4
    Last Post: 08-04-2002, 02:54 AM
  5. How to detect and open the default browser
    By sundeeptuteja in forum C++ Programming
    Replies: 1
    Last Post: 06-30-2002, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21