1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

JavaScript if else

Discussion in 'JavaScript' started by MrLeN, Dec 11, 2012.

  1. #1
    In Javascript, how can I write this:

    if (the referring website was http://www.mywebsite.com) {
    document.write("Great, let's write some stuff here!");
    }
    else {
    //the referrer was not appropriate so do just do nothing.
    }
     
    MrLeN, Dec 11, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    if (document.referrer == "http://www.mywebsite.com") {
      document.write("Great, let's write some stuff here!");
    }
    else {
      //the referrer was not appropriate so do just do nothing.
    }
    Code (markup):
    The else part isn't needed, so you can write
    if (document.referrer == "http://www.mywebsite.com") {
      document.write("Great, let's write some stuff here!");
    }
    
    Code (markup):
     
    Rukbat, Dec 11, 2012 IP
  3. MrLeN

    MrLeN Well-Known Member

    Messages:
    406
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Thanks. :)
     
    MrLeN, Dec 11, 2012 IP