Solved

Get Javascript URL parameters

Posted on 2016-10-31
7
61 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 56

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 56

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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

Author Closing Comment

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

Expert Comment

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

Expert Comment

by:Ray Paseur
ID: 41881024
0
 

Author Comment

by:petewinter
ID: 41881065
Many thanks Ray
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 dynamically set the form action using jQuery.

680 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