This is eventually the code I went with, which has been tested with IE 5/6, Mozilla/Netscape, and Opera.
############################################################################## open_url() - open a url in the system's default browser ############################################################################## USAGE: # &open_url( "http://127.0.0.1:8888/" ); # # OS SPECIFIC NOTES: # This routine loads the Win32::Shell module to execute the "open" # command which will open the browser and load the URL. However, if the # user has defined a local path to a browser, we try to open that instead. # # RETURNS: # 1; we instruct the user to open their browser if we can't. #############################################################################
sub open_url { my ($url) = @_; # we spit out our suggestion just to catch all instances. ¬e("If your browser doesn't load, go to <$url>", 1); # find out what browser we're using. use Win32::TieRegistry; my $browser = $Registry->{"Classes\\http\\shell\\open\\command"}->{'\\'}; ¬e("Your registry states that $browser is your default program."); # if a browser_path hasn't been set, try # to open the default browser using the native API. # note, that if the $browser is Opera, we skip # this part, because Opera uses a Multiple # Document Interface that crashes us every time. # instead, we use the "path to browser" code below. if ( $SETTINGS->{user}->{browser_path} eq "default" or $browser =~ /opera/i ) { use Win32::API; my $ShellExecute = new Win32::API("shell32", "ShellExecuteA", ['N','P', 'P', 'P', 'P', 'I'], 'N'); $ShellExecute->Call(0, "open", $url, 0, 0, 1); } # if a browser_path has been defined, try passing # the $url to the .exe and hope it understands. else { # if we see "program files" or "internet explorer", we take # a chance and try to change them to their common eight char # equivalents. this won't work for all users but covers # a good large portion of them. yup yup. fun. chicks on speed. $SETTINGS->{user}->{browser_path} =~ s/program files/progra~1/ig; $SETTINGS->{user}->{browser_path} =~ s/internet explorer/intern~1/ig; ¬e("Trying to load $SETTINGS->{user}->{browser_path}."); unless ( fork ) { system("$SETTINGS->{user}->{browser_path} $url"); } } return 1; } 1; -- Morbus Iff ( .sig on other machine. ) http://www.disobey.com/ && http://www.gamegrene.com/ "where's there's a will, there's a morbus ready to collect!"