Open the default browser in Ruby
Cross-platform solution:
First, install the Launchy gem:
$ gem install launchy
Then, you can run this:
require 'launchy'
Launchy.open("http://stackoverflow.com")
Open browser with URL in Ruby
It looks like you are pushing the Browser with too many urls at the same time.
Using sleep
seems to work fine.
15.times {|i| `open http://google.com?q=#{i}` }
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=5.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=6.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=12.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=14.
# => 15
15.times {|i| sleep(0.2); `open http://google.com?q=#{i}` }
# => 15
Open local HTML file in default web browser
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")
change Watir::Browser.new to IE by default
Yes you can do so. For that You have to change browser.rb file,
def initialize(browser = :firefox, *args)
to
def initialize(browser = :IE, *args)
and add IE extension on system path.
How do I launch a website (with GET parameters) in the default browser in Ruby?
Yep, it's pretty old Launchy's bug. It can be fixed adding ^
in the url before &
char (as the guy who opened an issue suggests). I'll make a patch ASAP. So, right now you can use just plain system
method for this job:
system("start http://google.com?a=1^&b2=2")
Related Topics
Understanding How Establish_Connection Works in Activerecord
Rails on Windows Is So Slow (Rails -V Takes 4 Seconds)
How to Extract a Sub-Hash from a Hash
Ruby and "You Must Recompile Ruby with Openssl Support or Change the Sources in Your Gemfile"
How to Uninstall Ruby from /Usr/Local
How to Url Encode a String in Ruby
Rails: How to Use Dependent: :Destroy in Rails
Trying to Set Up Postgres for Ror App, Getting Error - Fe_Sendauth: No Password Supplied
Routing Nested Resources in Rails 3
Install Rails 3 on Osx with Rvm
How to Remove Gem from Ruby on Rails Application
Sorting a Ruby Array of Objects by an Attribute That Could Be Nil
What Are the Differences Between "Private", "Public", and "Protected Methods"
How to Calculate the Distance Between Two Gps Coordinates Without Using Google Maps API
Dividing Elements of a Ruby Array into an Exact Number of (Nearly) Equal-Sized Sub-Arrays
Rails 3 - No Such File to Load -- Openssl
How to Embed Regular Expressions in Other Regular Expressions in Ruby