Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open local HTML file in default web browser

Tags:

ruby

IS there any way in Ruby to open a local HTML file in the user's default web browser? I could do something like:

system("open /path/to/file.html")

But that would only work on Mac OS X. Are there any solutions that work on any platform?

like image 876
Mark Szymanski Avatar asked Mar 05 '26 22:03

Mark Szymanski


1 Answers

You can use the launchy gem.

First, install the gem:

$ [sudo] gem install launchy

Then, in your ruby code:

require 'rubygems'
require 'launchy'

Launchy::Browser.run("/path/to/file.html")
like image 145
htanata Avatar answered Mar 08 '26 22:03

htanata



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!