urlにこのようなものが含まれていて、segment1が何かに等しい場合は、これを実行します...
http://stackoverflow.com/segment1/segment2
お気に入り:
if (segment1 = 'anyword')
{
..then do this
}
そんな感じ?
urlにこのようなものが含まれていて、segment1が何かに等しい場合は、これを実行します...
http://stackoverflow.com/segment1/segment2
お気に入り:
if (segment1 = 'anyword')
{
..then do this
}
そんな感じ?
あなたはURLを分割することができます:
var url = "http://stackoverflow.com/segment1/segment2";
var splits = url.replace('http://', '').split('/');
if(splits[1] == "segment1"){
}
あなたはこのようにそれを行うことができます
var myurl = "http://stackoverflow.com/segment1/segment2";
if(myurl.split('/')[3] == "segment1")
{
//your code
}
var s1 = "foo";
alert(s1.indexOf("oo") != -1);
また
if (/anyword/.test(self.location.href))
{
....
}
URLを分割して、各パス名などを確認することもできますが、URLに何かが含まれているかどうかを確認するだけの場合は、次のようにすることができます。
var url = 'http://stackoverflow.com/segment1/segment2';
if (url.indexOf('segment1') != -1) {
//do this
}