Ryan Burnette

Getting And Setting URL Query Parameters In JavaScript

I’ve been learning Ember.js lately and I’m excited using MVC frameworks in the browser. Without getting too far off the topic of this post before I even get started, I’ll mention what lead to write this library. Serializing app state into query parameters aren’t ready for primetime in Ember yet. But whether you’re using Ember or not, a quick and simple lib to get and set URL parameters can be pretty helpful.

I want to be able to deploy the current stable version of Ember while doing some light handling of URL parameters. I also have some situations where I want to save an interface state in URL parameters using pushState so that exact configuration is contained within the URL.

I looked around but couldn’t find a quick, easy to implement JavaScript lib that provided manipulation of the Window Location through URL parameters and pushing states into the browser history. I decided to write one because I knew I’d use it. Maybe you’ll use it too.

The project is called Qurl and it’s on Github. It’s a simple JavaScript library for getting and setting URL query parameters. It’s also easily installable as a Bower package.

This is especially useful for serializing the state of an interface into the address bar without any page reloads. If implemented correctly, this allows the user to bookmark or share the page URL without having to put any input in to return to the desired state.

I’m using it with Ember a little bit until their URL parameter support starts shipping enabled.