webcreator25
webcreator25

Reputation: 59

How to get index of something or something else from url

I'm trying to make something happen if the url contains a certain word, but the word needs to change from page to page, heres the code I've got…

if(window.location.href.indexOf('mens-' || 'footwear-') > -1 ){
 // do something here
} else {}

this works for 'mens-' but not for 'footwear-'

any ideas?

Thanks

Upvotes: 0

Views: 336

Answers (1)

cn0047
cn0047

Reputation: 17091

Agree with @Satpal, but you can try use regex, like this:

if (/(mens-|footwear-)/.test(window.location.href)) {
// do something here
} else {}

It is super simple example... and here I just try to get a gist...

Upvotes: 1

Related Questions