html - How to pre-populate specific text from specific referrers URLs to a search form? -


here´s problem: have html page search form, , need take specific parts of specific referrers urls , pre-populate them search form.

so user have click on search without manually entering query (as there).

here 2 examples referrers urls parameters , directories

1) http://www.bing.com/search?q=tiny+cats&form=mozsbr&pc=mozi (so if referrer bing.com, text "q" param. = "tiny+cats" in case)

2) http://cutestcatpics.com/tag/tiny-cats/pages/1.php (so if referrer cutestcatpics.com, text 2nd. level directory = "tiny-cats" in case)

here html page search form:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-  transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head>  <body> <form action="http://search.yahoo.com/search?p=" target="_blank" id="search-box">   <input type="text" name="q" size="31" />   <input type="submit" value="search" /> </form>  </body> </html> 

any cool dev can me this?

thanks in advance.

basically need use javascript parse referrer url , set input's value. here's starting point:

function getreferrervariable(variable) {     var referer = document.referrer;     var query = referer.split('?')[1];     if(typeof query === 'undefined') return '';     var vars = query.split('&');     (var = 0; < vars.length; i++) {         var pair = vars[i].split('=');         if (decodeuricomponent(pair[0]) == variable) {             return decodeuricomponent(pair[1]);         }     } }  function urldecode(str) {    return decodeuricomponent((str+'').replace(/\+/g, '%20')); }  var input = document.getelementsbyname("q")[0]; var term = urldecode(getreferrervariable('q')); input.value = term; 

here's working example: http://jsfiddle.net/ngehe/

now need modify code handle second case.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -