简体   繁体   中英

Using Javascript to display an ad based on Text on a page

I know what I want to do should be done with a database, but my programmers are backed up and I want to use some test code to test a concept.

I want to put up 1 of 5 unique ads on a page. The type of ad will be based on a piece of text located on the page.

For example I have 1000 pages showing homes for sale. If that home is in XYZ county, then I want to show an ad called XYZ.jpg. However if that home is in ABC County, then I want to show an ad called ABC.jpg

So can javascript scan a page and if a word is found, display certain text? Or if not scan a page, at least scan the "County" field.

Thanks!

if (document.innerText.indexOf('keyword') != -1) {
    document.getElementById('ad_div').innerText = "Found " + keyword + "!";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM