I have a url (e.g. http://www.youtube.com/watch?v=og9B3BEnBHo) and I'd like to add a parameter to it (wmode=opaque) so that its:
http://www.youtube.com/watch?v=og9B3BEnBHo&wmode=opaque
Can anyone tell me which function to use to make this work?
What Are URL Parameters? Also known by the aliases of query strings or URL variables, parameters are the portion of a URL that follows a question mark. They are comprised of a key and a value pair, separated by an equal sign. Multiple parameters can be added to a single page by using an ampersand.
URL parameter is a way to pass information about a click through its URL. You can insert URL parameters into your URLs so that your URLs track information about a click. URL parameters are made of a key and a value separated by an equals sign (=) and joined by an ampersand (&).
URL parameters (also called query string parameters or URL variables) are used to send small amounts of data from page to page, or from client to server via a URL. They can contain all kinds of useful information, such as search queries, link referrals, product information, user preferences, and more.
URLS and query parameters aren't secure. They should never contain sensitive or important information (passwords, static shared secrets, private information, etc).
require 'uri' uri = URI.parse("http://www.youtube.com/watch?v=og9B3BEnBHo") uri.query = [uri.query, "wmode=opaque"].compact.join('&') puts uri.to_s #edit Since 1.9.2 there are methods added to the URI module uri = URI.parse("http://www.youtube.com/watch?v=og9B3BEnBHo") new_query_ar = URI.decode_www_form(String(uri.query)) << ["wmode", "opaque"] uri.query = URI.encode_www_form(new_query_ar) puts uri.to_s
(The call to String
ensures that this also works in the case when the original URI does not have a query string)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With