jquery url builder/parser

xpepermint picture xpepermint · Dec 3, 2010 · Viewed 15.1k times · Source

I'm searching for a jquery plugin for full URL manipulation (parsing, building).

Example:

var url = 'http://mypage.com/?param=1'
var params = $.getParams(url) # {param: 1}
var newUrl = $.newUrl(url, {param:2}) # 'http://mypage.com/?param=2'

Thx.

Answer

Maksym Kozlenko picture Maksym Kozlenko · Apr 18, 2012

To convert a JavaScript object into a URL parameter string you can use the jQuery param method:

$.param({a:1, b:"Test 1"}) // gets: "a=1&b=Test+1"

To parse a URL parameter string into a JavaScript object use this solution.