Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Programmatically open browser with a given URL

    Dear All, this seems to be very easy, but somehow I don't find how do I open user's default browser with a particular URL?
    I can display a link in the output window with
    Code:
    display `"{browse "http://www.google.com":GOOGLE}"'
    but that requires the user to click it.

    How do I open it without a click? (I am looking for a robust platform-independent solution).

    Thank you, Sergiy Radyakin

  • #2
    I don't know whether Stata has a built-in facility for this, but if not, what about something like the following:
    Code:
    loc url http://www.stata.com
    if c(os)=="MacOSX" {
        !open `url'
    }
    else if c(os)=="Unix" {
        // requires xdg-utils
        !xdg-open `url'
    }
    else if c(os)=="Windows" {
        // just a guess -- I have no idea whether this will work or not
        !cmd /c start `url'
    }

    Comment


    • #3
      Thank you Phil.
      I used the same in the geochart.ado earlier, but I am now in search of a nicer/simpler and safer approach.
      I completely realize that there is a chance there is nothing better, but I hope to find one.

      For simplicity, I want to avoid branching by platform, that shouldn't be necessary, given that Stata has a facility to open the browser for links.
      For robustness, I've heard of -start- being disabled in some Win95, Win98, WinMe and some XP configurations for security reasons, without much details.
      How to do this is described here : http://windowsitpro.com/windows-serv...and-extensions didn't check the particular method, but sounds about right, and some behavioral changes that it causes are described here: http://www.robvanderwoude.com/ntstart.php
      There was a generational change somewhere at that time where start.exe was converted to a built-in command start, or the other way around, and I guess it was somehow related. No precise info, I am afraid.

      I haven't heard of it for a while, perhaps since the Vistas started to appear, but can't deny it might still occur. Additional requirements for Unix/Linux as you pointed also fall in this category. Importantly, I don't want to inadvertently start a wrong file in case the URL gets misunderstood, truncated, etc. Testing without access to a different platform is guesswork, as you rightfully commented and something like xdg-open can be misspelled in a number of different ways, which will not be apparent until someone bumps on it.

      If someone is on Linux/Unix and you don't have the xdg-utils: can Stata still open the links in output when you click them?

      Regards, Sergiy Radyakin

      Comment


      • #4
        Originally posted by Sergiy Radyakin View Post
        For simplicity, I want to avoid branching by platform, that shouldn't be necessary, given that Stata has a facility to open the browser for links.
        Agreed—I just don't know whether they expose that to the user/programmer.

        Comment


        • #5
          Just looked in the manual, and found the answer:
          Code:
          view browse http://www.stata.com/

          Comment


          • #6
            Perfect! Bingo! Just what I was looking for!
            Thank you very much, Phil !

            Comment

            Working...
            X