Skip to content Skip to sidebar Skip to footer

Condition To Test If A Word Exists In Window.location.href

I want to test if a word ['sublanguageid-all' to be specific] is present in the current address of the page using an 'if' condition. I've tried /sublanguageid-all/g, but I'm not ab

Solution 1:

Doesn't

if(window.location.href.indexOf('sublanguageid-all') != -1)

work?

Solution 2:

if( location.href.match("sublanguageid-all") ) { 
  alert('present') 
}

Solution 3:

you can simply try the includes(). Kindly refer following code.

if(window.location.href.includes('sublanguageid-all')) {
    // your code while it exists in the URL
}

Post a Comment for "Condition To Test If A Word Exists In Window.location.href"