SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question If URL Contains 'affiliate1' Then do. For example: www.MyUncleVinny.com?affiliate1

    I have a website www.MyUncleVinny.com. We use affiliate codes for financial reporting. For example: www.MyUncleVinny.com?affiliate1

    How can I write a simple JavaScript function that will look at the URL and determine if it contains "affiliate1" then do something, like display image1, if the URL contains "affiliate2", then display image2, else display image3.

    Thank you SO MUCH in advance.

  2. #2
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript contains an object called location which allows you to get the URL of the current page.

    Code:
    alert(location.href);
    That will alert the URL of the current page. In order to find if it has a certain string, you can use the String's search method:

    Code:
    location.href.search('affiliate1');
    I hope that helps.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •