php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Sunday, April 22, 2018

How to get URL parameters using JavaScript?

In this tutorial we are going to show you how to parse a URL and get values from the URL that you are passed.  

We will be using the JavaScript's built in function split() which splits the string from a separator which is passed as a parameter to this function. The result is stored as an array and we will be using it multiple times since we want to split data into key value pairs, as the server generally processes it. 

Just have a look at the following simple code.


var URL = "";

var query = URL.split('?')[1].split('&');

query.forEach(function(key) {
  var pair = key.split('=');
  alert(pair[0] + '=' + pair[1]);


URL will be split into parts based on the type of separators you are given in the function.
In this example we gave ('?', '&')

In forEach loop we are checking for the key and value pairs.
Those should be 

key1 = firstValue
value1 = name
key2 = secondValue
value2 = email

We are alerting the result that generated here.

For any queries please comment in the bellow comment section.
For more interesting and useful code snippets please follow our blog.


  1. Led Lights Sydneyobviously appreciate your site and you ought to write more.

  2. Thanks for giving me the useful information. I think I need it! Blackmart market helper Freestore

  3. Whats up! I just wish to give an enormous thumbs up for the good info you may have right here on this post. I will probably be coming back to your weblog for extra soon.Luminous Battery in Chennai

  4. Nice...Its highly informative post. I really enjoyed reading. Thanks
    SEO Expert in Pakistan

  5. I know this if off topic but I'm looking into starting my own blog and was wondering what all is needed to get set up? I'm assuming having a blog like yours would cost a pretty penny? I'm not very web smart so I'm not 100% positive. Any suggestions or advice would be greatly appreciated. Appreciate it hire agencies to generate more leads and sales

  6. Hi there, You've done a good job. I will certainly digg it and personally suggest to my friends. I believe they'll be benefited from this web site. Air Cargo Service

  7. Thanks for the wonderful information. We are also deal in Digital Signature Certificate in Delhi

  8. I loved as much as you will receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get got an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly a lot often inside case you shield this hike.
    build a Facebook ads campaign

  9. This is exactly what I was looking for. Thanks for sharing this great article. The quality of your articles and contents is great.
    Digital Signature Certificate in Delhi

  10. Great article indeed. very helpful. will surely recommend this to my friends.
    Private Detective Agency in Mumbai

  11. I highly admire your post. Thanks for sharing such wonderful information, I see your post very often and share them on all social media channels.
    Digital Signature Certificate in Delhi

  12. Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.

  13. Search 1000s of job offers and find the best suitable position. Jobs near me from direct employers no agencies or jobs direct from top recruitment agencies & recruitment consultants. Send your job application to apply for a job with one click.

    if you want more just look here "applytojobs"

  14. Advertise your job for fast, easy and effective recruitment. Reach thousands of candidates actively looking for a new job today

    if you want more just look here "jobsonly"


More Posts