Monday, February 21, 2011

Red And Blue Metal Core Wheels

Text search in your page with Javascript

If you search for text in web page or blog can easily be done through Javascript, which is a great value to the usability of your site especially if it addresses issues with lots of text, usually in many browsers can be done with window.find function (), but to work in almost all there is to include a small script. Var

Example:



Code:

Script:

\u0026lt;script language="JavaScript">
was crowded null

busca function (str) {
if (parseInt (navigator.appVersion) \u0026lt;4) return;
was strFound;
if (window.find) {

; strFound = self.find (str);
if (! strFound) {
strFound = self.find (str, 0,1)
while (self.find (str , 0.1)) continue
}

} else if (navigator.appName.indexOf ("Microsoft ")!=- 1) {

if (Trang ! = null) {
TRange.collapse (false)
strFound TRange.findText = (str)
if (strFound) TRange.select ()}

if (Trang == null ("Opera does not support search")
return;

} if (! StrFound) alert ("String '" + str + "' not found")
return;}


Form: \u0026lt;input
name="t1" value="Texto to Buscar" /> \u0026lt;input onclick = "search (document.all.t1.value)" type = "button" value = "Search" / >


Important: The script and the form you can put anywhere on your site, but we recommend that you include the script in the \u0026lt;head> \u0026lt;/ head> of your page, but not quite necessary, as you see in this blog that does not copy the script in the \u0026lt;head> but if I put it first in the entry and working properly.




As you can see the text box has the name = "t1", so the button is in the OnClick event searches function which sends the object's Value t1 .



0 comments:

Post a Comment