1

Can I extract the search term or keyword of the search engine address using javascript in my html website? I already have made a javascript showing the address of the incoming address of the referrer using the

document.write(document.referrer);

but I can't figure out how to extract or parse the search term and displaying it it in my website with backlinks for the referrer.

I want to make it a javascript code that could generate the incoming search term for me with backlinks to the referrer. I'm new to JavaScript stuff perhaps you could provide me a simple and understandable steps in making it . Thanks

4
  • Possible duplicate: stackoverflow.com/questions/2680328/query-string-in-javascript Commented Apr 9, 2012 at 11:06
  • hi i checked the link but I cant understand how to use the query string function . I tried to enclose it in as a javascipt and inserted it in my website but it did not return any value of the queries made by google when a visitor arrived in my website. I want a simple explanaition about a javascript that writes the incoming search term in as they arrive in my website . thanks for helping Commented Apr 9, 2012 at 15:41
  • It's still not clear what you're actually asking. Are you trying to extract a search/querystring out of the referrer? Commented Apr 9, 2012 at 22:22
  • Yes. I would like to extract the search term out of the referrer url . I need a javascipt code that could extract and display/write the search term. Commented Apr 9, 2012 at 22:28

1 Answer 1

0

document.referrer.split('?')[1]

split divides the string it's operating on (document.referrer) at the character specified (?). It creates an array of two elements, the first (index 0) containing the string before the question mark; the second (index 1) the characters after the question mark.

Thus that expression returns the characters after the ? in document.referrer.

Sign up to request clarification or add additional context in comments.

4 Comments

is document.referrer.split('?')[1] the complete code already that can be used to display the incoming search term for my site? how about the document.write(document.referrer) , how sould I combine it? Im just starting to learn JavaScript programming I hope you could make the explanation more simple
That expression gets you what you want. How you use it is up to you. document.write(document.referrer.split('?')[1]) will output the result.
Thanks andrew the code worked but it only shows the whole characters after "?". I was expecting for the search terms typed in the search engine and not the long characters. how could I add some parameters that could filter the undesirable character?
You haven't given any information about what to look for, or the string you actually have. I suggest asking another question along the lines of "I have a string '......': how do I use JavaScript to extract '......' from it?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.