I have the function below, which puts the query into an object. It works but adds the url to the object and Im not really regex savy enough to work out how to remove the url and only include the vars.
function urlToObj(url)
{
var obj = {};
url.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { obj[$1] = $3; }
);
return obj;
}
E.g.
url = http://www.example.com/hello/world.php?var1=1&var2=2
url = http://www.example.com/hello/world.asp?var1=1&var2=2
url = http://www.example.com/hello/world?var1=1&var2=2
obj = urlToObj(url);
Output
obj { var1="1", var2="2", http://www.example.com/hello/world.php="" }
obj { var1="1", var2="2", http://www.example.com/hello/world.asp="" }
obj { var1="1", var2="2", http://www.example.com/hello/world="" }
I would like it to remove the urls so it looks like this
obj { var1="1", var2="2" }
Any examples and info where I am going wrong would be great.
Thanks
This extension creates a singleton query string object for quick and readable query string modification and creation. This plugin provides a simple way of taking a page’s query string and creating a modified version of this with little code.
http://archive.plugins.jquery.com/project/query-object