// http://tutorialzine.com/2013/07/quick-tip-parse-urls/

$(function(){

    // The URL we want to parse
    var url = 'http://example.com/things/?key=value#comments';

    // The magic: create a new anchor element, and set the URL as its href attribute.
    // Note: accessing the DOM element inside the jQuery object with [0]
    var a = $('<a>', { href:url } )[0];

    var hostname = a.hostname; // example.com
    var path = a.pathname; // /things/
    var query = a.search; // ?key=value
    var hash = a.hash; // #comments
    var posr = a.port;
    var protocol = a.protocol;
    var origin = a.origin // not available in older IE versions

});