Detect Homepage

Discussion in 'JavaScript' started by adamjblakey, Jun 14, 2010.

  1. #1
    Hi,

    I dont know where to start with this really. I need an if statement which checks if the user is on the homepage. If they are then it shows some text and if not it doesn't.

    Any ideas?

    Cheers,
    Adam
     
    adamjblakey, Jun 14, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    Not sure why code like that is needed as you can do this via html/php or asp.net but here it is. (I haven't tested it yet)

    
    if (document.location=='http://www.mywebsite.com/') {
       document.write('You are on the homepage');
    }
    
    Code (markup):
     
    stephan2307, Jun 14, 2010 IP
  3. helvetica

    helvetica Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    if(window.location.pathname="index.php")
    {
    alert('It is index');
    }else
    {
    alert('Not an index.')
    }
    PHP:
     
    helvetica, Jun 14, 2010 IP