Home > front end >  How to get the user search keywords, and then display in the page
How to get the user search keywords, and then display in the page

Time:10-22

The function GetQueryString ($name) {
Var $index=document. The referrer. IndexOf ($name + "="), $e=' ';
If ($index> 1) {
$e=document. The referrer. Substring ($index + $name. Length + 1);
If (($index=$e.i ndexOf (" & amp;" )) & gt; 0 {
$e=$e.s ubstring (0, the $index);
}
}
Return $e;
}
//call the method
Var $wd=GetQueryString (" wd ");
If ($wd& & $4 wd. Length> 0) {} else {$wd=GetQueryString (" word ")}
If ($wd& & $4 wd. Length> 0 {
$wd=decodeURIComponent ($wd);
$line='hello! I am & lt; Span style="color: # F00" & gt; The doctor & lt;/span> About [" & lt; b> '+ $wd + & lt;/b> "] Health, & lt; Span & gt; Do you have anything to consulting? ';

} else {

$line='hello! I am & lt; Span style="color: # F00" & gt; The doctor & lt;/span> What do you want to consulting,? ';
}
$(' # GJZ '). The HTML ($line);

CodePudding user response:

Baidu to do the transfer page document. The referrer get only transfer page, is no longer simply a keyword search after page, can't get search words

Web development learning materials recommended
JqGrid events
Web front-end development

CodePudding user response:

Request

CodePudding user response:

Document. The referrer get stops links to extract the keywords

CodePudding user response:

If you just want to in the current page of the search keywords to do that kind of mark red processing, is very simple, get into the body character STR, with STR. Replace (/XXX/g, '& lt; Span style="color: # F00" & gt; Xxx '); Replace regular way can achieve full replacement, not only find the first replacement,
  • Related