How to get Uri with Javascript (ParseUri)

This should be useful to get the url uri… it will become an object so just add youvar.path or something, if you console.log the variable it should divide into 10 variable that you can choose to display.

[code]

function parseUri(sourceUri){
var uriPartNames = [“source”,”protocol”,”authority”,”domain”,”port”,”path”,”directoryPath”,”fileName”,”query”,”anchor”];
var uriParts = new RegExp(“^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(d*))?)?((/(?:[^?#](?![^?#/]*.[^?#/.]+(?:[?#]|$)))*/?)?([^?#/]*))?(?:?([^#]*))?(?:#(.*))?”).exec(sourceUri);
var uri = {};

for(var i = 0; i < 10; i++){
uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : “”);
}
return uri;
}

[/code]