tags:

views:

280

answers:

3

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

+2  A: 
if( location.href.match("sublanguageid-all") ) { 
  alert('present') 
}
duckyflip
The match function takes, as its only argument, a regular expression, not a string - https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/String/Match
David Dorward
+6  A: 

Doesn't

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

work?

Jimmy Stenke
+1. I avoid regex for simple substring matches as well.
Grant Wagner
A: 

I want if the url has particular string like(w3calculator.com/info/LINUX/...) then it have tobe redirected to http://info.w3calculator.com

Math