Skip to content


Subversion checkout URL

You can clone with
Download ZIP
url() - A simple, lightweight url parser for JavaScript
JavaScript CSS HTML


A simple, lightweight url parser for JavaScript (~1.6 Kb minified, ~0.6Kb gzipped).

Also available for Node.js.


For path(1) and path(-1) will always act as if the path is in the form /some/path/ regardless of whether the original path was /some/path or /some/path/.

url();            //
url('domain');    //
url('hostname');  //
url('sub');       // www
url('.0')         // (an empty string)
url('.1')         // www
url('.2')         // example
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');      // null
url('#');         // test=hash&chucky=cheese
url('#chucky');   // cheese
url('#poo');      // null

We can also pass a url in and use all the same options on it:

url('domain', '');            //
url('hostname', '');          //
url('sub', '');               // test.www
url('protocol', '');               // http
url('path', '');       // /some/path
url('port', '');       // 8080
url('protocol', '');  // https


Also include is a jQuery version of the plugin that can be called via $.url() with all the same options. If you're already using jQuery it may be better to use the jQuery version to avoid namespacing issues.


If you want to use Grunt you will need to install the required plugins locally using npm install in the root folder of your project. If you need to setup Grunt on your system you can follow my Setting up Grunt.js guide.



MIT licensed

Copyright (C) 2011-2012 Websanova

Something went wrong with that request. Please try again.