How to check if url contains a sub-string using jQuery or javascript?


How do i check if the current URL contains the sub-string using jQuery or javascript?

I need to select a anchor tag using class if a condition is met, suppose i need to check if URL has "/CRM" then select

if(URL.hasString('/CRM'))
{
$(".SelectURL").RemoveClass('Hide');
}

How to do it using jQuery or javascript?


Asked by:- Sam
0
: 709 At:- 11/13/2017 11:42:46 AM
javascript check if url contains string jquery check if url has parameters javascript






1 Answers
profileImage Answered by:- jaya

You can check if a string contains substring in javascript by taking the URL using windows.location.href and then check the sub-string using .IndexOf("Substring") method , so your complete code will be as below

if (window.location.href.indexOf("/CRM") > -1) {
   alert("Inside /CRM");
}

Or Second Method you can do it like below

if (location.href.match(/CRM/)) {
alert("in CRM ");
}
1
At:- 11/14/2017 7:58:35 AM
thanks, i tired method first only and it is working as needed 0
By : Sam - at :- 11/16/2017 12:16:33 PM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use

Subscribe Now

Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly