Launch web page from my application

前端 未结 6 887
误落风尘
误落风尘 2021-02-14 09:43

Ok, this probably has a really simple answer, but I\'ve never tried to do it before: How do you launch a web page from within an app? You know, \"click here to go to our FAQ\",

6条回答
  •  耶瑟儿~
    2021-02-14 10:42

    For the record (since you asked for a cross-platform option), the following works well in Linux:

    #include 
    #include 
    
    void launch(const std::string &url)
    {
      std::string browser = getenv("BROWSER");
      if(browser == "") return;
    
      char *args[3];
      args[0] = (char*)browser.c_str();
      args[1] = (char*)url.c_str();
      args[2] = 0;
    
      pid_t pid = fork();
      if(!pid)
        execvp(browser.c_str(), args);
    }
    

    Use as:

    launch("http://example.com");
    

提交回复
热议问题