0

i'm creating a project which needs the keywords from search engines to show users.

i have tried document.referrer but it shows only referrer domain.

if user searches like "buy a pc" then this url is generating by google

https://www.google.com/search?q=buy+a+pc&oq=buy+a+pc&aqs=chrome..69i57j5j0l2j69i61.1674j0&sourceid=chrome&ie=UTF-8#psj=1&q=buy+a+pc

now i need this url when user choose the my website or my site page from google results to extract keywords from url but i have to do this by javascript only.

Thanks.

Parth Parmar
  • 101
  • 1
  • 2
  • 17

2 Answers2

2

What you're looking for is in document.referrer

Collin Grady
  • 2,226
  • 1
  • 14
  • 14
  • no bro i'm looking for to get referrer url with parameters i tried document.referrer but it shows only domain, not parameters – Parth Parmar Sep 15 '13 at 00:41
  • Yes, I know. And if available, it will be in `document.referrer`. If that is empty, you do not have a referrer URL available to read. Referrers are not guaranteed to be passed to every page. – Collin Grady Sep 15 '13 at 00:42
  • document.referrer only shows http://www.google.com/ any other way to get referrer url with parameters ? – Parth Parmar Sep 15 '13 at 00:43
  • 1
    `document.referrer` will show you everything you have available. End of story. If it isn't in there, you can't get it. http://i.imgur.com/OP3ZQ3y.png - as you can see here, it *can* contain parameters. – Collin Grady Sep 15 '13 at 00:44
-2
function getParameterByName(name,url) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(url);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}


alert(getParameterByName('q','https://www.google.com/search?q=buy+a+pc&oq=buy+a+pc&aqs=chrome..69i57j5j0l2j69i61.1674j0&sourceid=chrome&ie=UTF-8#psj=1&q=buy+a+pc'));
Shemeer M Ali
  • 1,030
  • 15
  • 39