# Open a URL in a new browser tab?

**URL:** <https://www.ruby-forum.com/t/open-a-url-in-a-new-browser-tab/87487>\
**Category:** Ruby\
**Created:** [March 2, 2007, 11:25pm UTC](https://www.ruby-forum.com/t/open-a-url-in-a-new-browser-tab/87487 "2007-03-02T23:25:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clifford\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/49beb7/32.png) [@Clifford\_H](https://www.ruby-forum.com/u/Clifford_H)\
**Post date:** [March 2, 2007, 11:25pm UTC](https://www.ruby-forum.com/t/open-a-url-in-a-new-browser-tab/87487/1 "2007-03-02T23:25:43Z")

</div>

Sounds like the sort of thing that must already exist, but I can’t  
find it…

Is there a standard cross-platform way in Ruby to drive the user’s  
default web browser to open a URL in a new window/tab? Because if  
not, I have code samples for all major platforms and will create a  
gem.

I have this notion of using ruby2exe to turn a Camping app into an  
single executable that opens in the browser, without having anything  
pre-installed on the target machine… and that needs the open-URL  
feature.

Clifford H…

---

<div class="post-metadata">

**Author:** ![Clifford\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/49beb7/32.png) [@Clifford\_H](https://www.ruby-forum.com/u/Clifford_H)\
**Post date:** [March 4, 2007, 7:05am UTC](https://www.ruby-forum.com/t/open-a-url-in-a-new-browser-tab/87487/2 "2007-03-04T07:05:30Z")

</div>

Can it really be that I’m the only person that’s ever wanted this?

Mechanize and the like make it easy to act as a web client, and  
various tools act as a server, but the case of a web app that  
should run and display on a local system can’t really be that  
unique, can it?

Ok, I guess up up for a new gem… sometime.

Clifford H…

---

<div class="post-metadata">

**Author:** ![Clifford\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/49beb7/32.png) [@Clifford\_H](https://www.ruby-forum.com/u/Clifford_H)\
**Post date:** [March 4, 2007, 10:09am UTC](https://www.ruby-forum.com/t/open-a-url-in-a-new-browser-tab/87487/3 "2007-03-04T10:09:40Z")

</div>

Clifford H. wrote:

> Is there a standard cross-platform way in Ruby to drive the user’s  
> default web browser to open a URL in a new window/tab? Because if  
> not, I have code samples for all major platforms and will create a  
> gem.

Does “all major platforms” include Linux/Unix? If so, how do you find  
out what  
the user’s default browser is there?

---

<div class="post-metadata">

**Author:** ![Clifford\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/49beb7/32.png) [@Clifford\_H](https://www.ruby-forum.com/u/Clifford_H)\
**Post date:** [March 4, 2007, 11:38am UTC](https://www.ruby-forum.com/t/open-a-url-in-a-new-browser-tab/87487/4 "2007-03-04T11:38:44Z")

</div>

Code for each browser is most appropriate, but some browsers lie or  
can lie when doing browser sniffing.  
So this is probably (currently) unreliable.  
New Tab or New Window is, like CSS often up to the user ultimately,  
so probably better if you don’t try to control it.  
Better to aim for reliably predictable functionality

---

<div class="post-metadata">

**Author:** ![Clifford\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/49beb7/32.png) [@Clifford\_H](https://www.ruby-forum.com/u/Clifford_H)\
**Post date:** [March 4, 2007, 12:10pm UTC](https://www.ruby-forum.com/t/open-a-url-in-a-new-browser-tab/87487/5 "2007-03-04T12:10:46Z")

</div>

Sebastian H. wrote:

> Does “all major platforms” include Linux/Unix? If so, how do you find out what  
> the user’s default browser is there?

The browser will often be already running, and I expect that most X11  
browsers will have adopted the Netscape procedure (using X properties,  
I have code for that from years ago) to be told which URL to open. I  
don’t think it distinguishes windows from tabs, but that’s not really  
for the caller to control anyhow.

If the X display variable isn’t set, or the relevant properties aren’t  
on the display, then you need to either fail or start a browser. A  
list of several of the most popular would be an acceptable way to  
start, and a preferred-browser environment variable would allow  
customization after that.

Clifford H…
