How can I add http://
to a URL if it doesn't already include a protocol (e.g. http://
, https://
or ftp://
)?
Example:
addhttp("google.com"); // http://google.com
addhttp("www.google.com"); // http://www.google.com
addhttp("google.com"); // http://google.com
addhttp("ftp://google.com"); // ftp://google.com
addhttp("https://google.com"); // https://google.com
addhttp("http://google.com"); // http://google.com
addhttp("rubbish"); // http://rubbish
mozilla.org
alone, how would you know if it should be,http
,https
orftp
? – Ilene