ppp has asked for the wisdom of the Perl Monks concerning the following question:

I have done lot of google search and come across the conclusion to ask here at last.I found in built function to open the default browser like this :

my $url = 'file:///www.google.com/'; open_browser($url);

But how to close the browser , I couldn't find any way to close the default browser ? Any help perl experts.. please ?

Replies are listed 'Best First'.
Re: How to close the default browser in perl
by Corion (Patriarch) on Jan 19, 2015 at 07:44 UTC

    There is no common way of "closing the default browser". That is usually up to the user.

    If you specialize towards a browser, like Firefox with mozrepl installed, or Firefox on Linux, there are commands that can close a browser tab that was previously opened. But in the general case, that is not possible.

Re: How to close the default browser in perl
by Discipulus (Canon) on Jan 19, 2015 at 08:27 UTC
    hello,
    some notes; open_browser is not a builtin, is part of Browser::Open and this module seems able to guess which command execute (via system) and expose such command via his function open_browser_cmd. It seems to me that such module is a bit old/unmaintained/abandoned and if you look at source code it does a very little work. that said that module seems to have only few errors in compatibility matrix (also the module tests are very simple) so you can easily spot the right browser's command (by your own or using the module) and open that process storing the associated PID, with the PID you can kill the program at your will.

    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Note that killing the browser process will likely also kill all other browser windows and browser tabs that are currently open. A user might not be amused if a program does stuff like that.

        yes, of course. This may heavely depends on th OS, i think. in win7 for example there is a PID for every tab open and if you kill such PID the tab only goes in error if is a tab in a group. if you close a 'main' window via kill you kill all windows at same time, and is not a nice thing.

        Please ppp note that 'default browser' is only a facility of an OS not a Perl concept.

        L*
        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: How to close the default browser in perl
by locked_user sundialsvc4 (Abbot) on Jan 19, 2015 at 17:29 UTC

    Of more concern to me, as an end-user, would be the simple fact that your Perl program, running at computer-speed, would close “my” browser window (or tab) when it wanted to, not when I wanted to.   This is not good user-interface karma.

    I would expect you to provide some kind of JavaScript-driven button, which I could press when I was ready, which would close the window.   (Certain restrictions apply:   to close a window in JavaScript, you must have opened it in JavaScript.)   This button should also notify your Perl script when I am (damn well ...) ready to proceed.   I should be free to keep that window open for as long as I wish.   And then, the action is initiated and completed from within the browser (JavaScript) environment, not externally by shooting holes in PIDs.