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.

Javascript contains an object called location which allows you to get the URL of the current page.


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:


location.href.search('affiliate1');

I hope that helps.