admin管理员组

文章数量:1357294

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 able to put it in an if-statement

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 able to put it in an if-statement

Share Improve this question asked May 22, 2009 at 13:40 yogeshmangajyogeshmangaj
Add a ment  | 

3 Answers 3

Reset to default 6

Doesn't

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

work?

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

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
}

本文标签: javascriptCondition to test if a word exists in windowlocationhrefStack Overflow