http://rob:abcd1234@www.domain.com/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese
url(); // http://rob:abcd1234@www.domain.com/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese
url('hostname'); // www.domain.com
url('domain'); // domain.com
url('tld'); // com
url('sub'); // www
url('.0') // (an empty string)
url('.1') // www
url('.2') // domain
url('.-1') // com
url('auth') // rob:abcd1234
url('user') // rob
url('pass') // abcd1234
url('port'); // 80
url('protocol'); // http
url('path'); // /path/index.html
url('file'); // index.html
url('filename'); // index
url('fileext'); // html
url('1'); // path
url('2'); // index.html
url('3'); // (an empty string)
url('-1'); // index.html
url(1); // path
url(2); // index.html
url(-1); // index.html
url('?'); // query1=test&silly=willy
url('?silly'); // willy
url('?poo'); // (an empty string)
url('#'); // test=hash&chucky=cheese
url('#chucky'); // cheese
url('#poo'); // (an empty string)
We can also pass a url in and call all the same options on it:
url('sub', 'test.www.domain.com/path/here'); // test.www
url('protocol', 'www.domain.com/path/here'); // http
url('path', 'http://www.domain.com:8080/some/path'); // /some/path
url('port', 'http://www.domain.com:8080/some/path'); // 8080
url('protocol', 'https://www.domain.com:8080/some/path'); // https
etc...
jQuery Plugin Development BoilerplateThe Ultimate Guide to Writing jQuery Plugins
10 Awesome jQuery Rating Plugins
10 Awesome jQuery Tag Cloud Plugins
12 Awesome jQuery Selector Extensions
This plugin looks great! I am frequently disappointed that js doesn’t include richer url parsing tools, so great job adding this needed functionality.
One question: is this a jQuery plugin, or vanilla javascript?