Forum Moderators: open

Message Too Old, No Replies

Getting google search terms highlighted on your page

not sure where to post or what to ask?

         

willeffects

3:20 am on Apr 14, 2005 (gmt 0)

10+ Year Member



Sometimes when you search on google and click on a result the page you end up on inserts your search term into their search box or highlights it on their page.

What is used to accomplish this?

Thanks,
Will

tedster

6:21 am on Apr 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It takes a bit of scripting - you can't do it with plain old HTML. But a server script can capture the referer string in the HTTP header, and then strip out the search terms from that string.

Then you can use CSS to highlight the terms the server split off as variables for you. In fact, our Site Search does this.

willeffects

8:39 am on Apr 14, 2005 (gmt 0)

10+ Year Member



Ah thank you that makes sense. So you have your backend assign a class to the terms you want to highlight?

We use php btw.

Will

dcrombie

1:11 pm on Apr 14, 2005 (gmt 0)



It can also be done after the page has loaded - using JavaScript. I find a hybrid solution most effective - PHP to detect the search string and pass it to JavaScript which handles the highlighting.

;)

willeffects

4:21 pm on Apr 14, 2005 (gmt 0)

10+ Year Member



Can you share the the js? Im not sure how to do that, but it seems that would be best on the server.

dcrombie

10:21 am on Apr 15, 2005 (gmt 0)



There are plenty of examples here [google.com] ;)