Skip to content

Instantly share code, notes, and snippets.

@JiLiZART
Forked from jlong/uri.js
Created April 23, 2012 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JiLiZART/2468612 to your computer and use it in GitHub Desktop.
Save JiLiZART/2468612 to your computer and use it in GitHub Desktop.
jQuery url parser
(function($) {
function parseUrl(url) {
var parser = document.createElement('a');
parser.href = url; //"http://example.com:3000/pathname/?search=test#hash";
return parser;
};
/**
* url.protocol; // => "http:"
* url.hostname; // => "example.com"
* url.port; // => "3000"
* url.pathname; // => "/pathname/"
* url.search; // => "?search=test"
* url.hash; // => "#hash"
* url.host; // => "example.com:3000"
*/
$.url = parseUrl(window.location.href);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment