Posted in Code Snippets, Javascript

Get query string value

Get the value of a field from query string using JavaScript:

function getURLParameter(name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)
                              [1].replace(/\+/g, '%20'))||null

When your URL is something like this:

Call the function like this:

var author = getURLParameter('author');

now variable author has james in it.


2 thoughts on “Get query string value

  1. I’ll immediately grab your rss as I can’t to find your e-mail subscription link or e-newsletter service.
    Do you’ve any? Kindly let me know in order that I may just subscribe.

    Liked by 3 people

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s