How can I close a specific browser window under linux
May 5, 2008 9:19 AM   Subscribe

Can I control a browser from an application under linux.

My application has an option to run as an http server, and kick off a browser that points to itself using (for example) /usr/bin/mozilla.
I want to add a quit button to the generated html, which tells the application to quit serving, then closes the browser, window, or tab that was created.
Obviously I dont want to quit any other windows or tabs if the user is doing something else at the time.
Stopping the server is no problem, but I'm hitting a roadblock closing down the browser side. Javascript wont let me close the current window, and I cant find any command line options to mozilla that let me do what I want.
Is there something I'm missing, or a better approach to the problem?
posted by yetanother to Computers & Internet (6 answers total)
 
Rather than "remotely controlling" the browser, couldn't you have the script that starts it also kill it?

You could have the "quit" button send a signal to the backend daemon you've written, which would read the process ID Firefox got started as (since it started it!) and send a kill signal to it.

The big wrinkle is that they may very well have opened other tabs and be irritated. I think it may be better design to just display a, "The server has been stopped. You may now close your browser window" message. I don't know the specifics, but I'd be annoyed if the browser just closed.
posted by fogster at 9:36 AM on May 5, 2008


record the pid when mozilla is launched, and have the server kill the process via the pid before it shuts down.
posted by jrishel at 9:36 AM on May 5, 2008


When the browser process is started, store the browser's process ID. When the user hits to quit button, use the PID to kill it.
posted by Blazecock Pileon at 9:37 AM on May 5, 2008


Response by poster: Recording the PID wont work, for the reasons outlined by fogster - I really don't want to kill any other windows that have been opened, or that were open before mine.
posted by yetanother at 9:41 AM on May 5, 2008


You could embed an HTML rendering engine inside your own client application, and then you don't have to worry about Mozilla.
posted by Blazecock Pileon at 9:43 AM on May 5, 2008


I think fogster's "And now you can close this window" suggestion is spot-on. I, for one, would be somewhere between annoyed and angry if my browser killed itself - in particular, I'd want to see "The server successfully shut down" so I know that, y'know, my browser didn't just crash on me.
posted by Tomorrowful at 9:49 AM on May 5, 2008


« Older you like-a tha juice, eh?   |   How do I squeeze the most value out of my lifeless... Newer »
This thread is closed to new comments.