Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I want to do something very simple; launch the default browser in Win32 to go to a specified URL.

I've tried all the methods below; however, none seems to be a perfect solution.

For instance, I can use the easiest method, which is simply: system("start http://www.perlmonks.org/") but that opens a console window, and this is a GUI app, so that's an undesirable result. Plus, there is a delay of at least 10-15 seconds in launching Netscape. I'm not sure if there would be the same delay with IE or another browser, but it seems to take forever. Maybe this is a bug in Win32 but I can't just accept this solution.

I can use Win32:Process to avoid the console window opening, but the delay is still there. Note that using the "start" command from the MS-DOS window does not have a delay; it's only when I call it from perl.

I can get rid of the delay by calling the browser executable directly. To do that I use Win32::Registry to get the path to the browser:

use Win32::Process; use Win32::Registry; my $browsekey; my %vals; $main::HKEY_CLASSES_ROOT->Open('HTTP\shell\open\command', $browsekey) +|| die "Open f]ailed: $!"; $browsekey->GetValues(\%vals); my $default_browser = $vals{''}[2]; $default_browser =~ s/\.exe\s*(.*)/\.EXE/i; my $browser; Win32::Process::Create($browser, $default_browser, "$default_browser "http://www.perlmonks.org", 0, NORMAL_PRIORITY_CLASS, ".") || return 0;
This works on my system, but when I sent this to a friend it did not work on hers. I didn't really like this method anyway, there has to be an easier way.

So, I used the Win32:OLE example from Learning Perl on Win32:

use Win32::OLE; my $browser = CreateObject OLE "InternetExplorer.Application.1" || r +eturn 0; $browser->{'Visible'} = 1; $browser->Navigate("http://www.perlmonks.org/");
This works fine, except I'm now forcing the user to use IE instead of Netscape. And it's possible (not likely I realize) that they don't even have IE. So what happens then?

So, is there a generic way to call the default browser on Win32 that is guaranteed to work properly on any normal system?


In reply to How do I launch my browser in Win32 to go to a specified URL? by httptech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-18 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found