How does a website highlight search terms you used in the search engine?

后端 未结 3 1851
眼角桃花
眼角桃花 2020-12-11 03:08

I\'ve seen some websites highlight the search engine keywords you used, to reach the page. (such as the keywords you typed in the Google search listing)

How does it

3条回答
  •  囚心锁ツ
    2020-12-11 03:31

    Basically, you...

    1. Examine document.referrer.
    2. Have a list of domains to GET param that contains the search terms.

      var searchEnginesToGetParam = {
          'google.com' : 'q',
          'bing.com' : 'q'
      }
      
    3. Extract the appropriate GET param, and decodeURIComponent() it.

    4. Parse the text nodes where you want to highlight the terms (see Replacing text with JavaScript).
    5. You're done!

提交回复
热议问题