Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Get Javascript URL parameters

Posted on 2016-10-31
7
56 Views
Last Modified: 2016-11-09
I am using jPList - jQuery Data Grid Controls - http://jplist.com

and I am using the deep linking feature: http://jplist.com/documentation/deep-links

which creates an URL parameter on filter change.

I am getting a parameter like the below...

http://www.domain.com/hardware/printers//hardware/printers/#sort:path~type~order=.title~text~asc|category-checkbox-dropdown:pathGroup=.vutek_mid_range~.vutek_high_volume|range-slider-print-width:prev~next=0~3200

Open in new window


Can you please tell me how I would get the relevant parameter to use within the page?

For example I would like to say...

If  "category-checkbox-dropdown:pathGroup" includes ".vutek_mid_range" return "Yes"?

I would prefer to use php for this, but if not Jquery is fine.
0
Comment
Question by:petewinter
  • 3
  • 3
7 Comments
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 41866980
I would prefer to use php for this, but if not Jquery is fine.
PHP is server side, jQuery is client side - they are not interchangeable

Where do you want to use this information?  

Please describe a use case.
0
 

Author Comment

by:petewinter
ID: 41867008
Hi Julian

Thanks for the reply and sorry for the confusion.

I will be linking to this parameter from another page. So when the page loads I only want to show a particular block of code if the parameter exists.

So if I was using php I would generally use code like the below...

if ( $_GET['parameter'] == "xxx") { .... }

Open in new window


And something similar for jQuery.

Hope that makes sense?
0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41867052
Just had a look at your URL again - the data you want is in the hashtag which is not sent to the server so you don't have a PHP option

JavaScript
<script>
function checkFor(key, value)
{
  var parts = window.location.hash.substr(1).split('|');
  for(var i in parts) {
    if (parts[i].indexOf(key) != -1) {
      if (parts[i].indexOf(value) != -1) {
        return true;
      }
    }
  }
  return false;
}
if (checkFor('category-checkbox-dropdown:pathGroup', '.vutek_mid_range')) {
  alert('yes');
}
else {
  alert('no');
}
</script>

Open in new window

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Closing Comment

by:petewinter
ID: 41867061
Perfect. Many thanks
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 41867076
You are welcome.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 41881024
0
 

Author Comment

by:petewinter
ID: 41881065
Many thanks Ray
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question