Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  74] [ 5]  / answers: 1 / hits: 23945  / 13 Years ago, mon, september 26, 2011, 12:00:00

I just need a simple function that will search the current url for a string (ie nature) and then will add a class to an object. I keep finding ways to search the query, but I want to search the entire url. If possible, without jQuery. If not, jQuery will work.


More From » javascript

 Answers
22

You can get the URL with window.location.href, and search it however you like:



var location = window.location.href;
if(location.indexOf(whatever) > -1) {
//Do stuff
}


window.location returns a Location object, which has a property href containing the entire URL of the page.


[#89916] Saturday, September 24, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chauncey

Total Points: 377
Total Questions: 91
Total Answers: 99

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
;