Leveraging doc.location & HTML element creation
Create a fake DOM element to utilize document.location properties
by Steven Senkus
HTML
<!--
https://gist.github.com/jlong/2428561
-->
JavaScript
function parseUrl(url) {
var aTag = document.createElement('a');
var locationKeys = _.keys(document.location);
var obj = {};
aTag.href = url;
_.each(locationKeys, function(key) {
if (!_.isUndefined(aTag[key]) && !_.isFunction(aTag[key])) {
obj[key] = aTag[key];
}
});
return obj;
}
var datUrl = 'http://www.dat.test1.datqa.com/Freight-Rates/promotion2.aspx?openNewWindow=true';
console.log(parseUrl(datUrl));