Prikazi cijelu temu 21.09.2010 21:49
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Lokacija:Tuzla


Predmet:Kod za trazenje na stranici.
Kod za trazenje na stranici.


PreuzmiIzvorni kôd (Javascript):
  1. <script language="JavaScript">
  2. /*
  3. Nadji na stranici-
  4. Posjetite [URL="http://www.icentar.com/"]http://www.icentar.com[/URL]
  5. */
  6. var NS4 = (document.layers);    // Which browser?
  7. var IE4 = (document.all);
  8. var win = window;    // window to search.
  9. var n   = 0;
  10. function findInPage(str) {
  11.   var txt, i, found;
  12.   if (str == "")
  13.     return false;
  14.   // Find next occurance of the given string on the page, wrap around to the
  15.   // start of the page if necessary.
  16.   if (NS4) {
  17.     // Look for match starting at the current point. If not found, rewind
  18.     // back to the first match.
  19.     if (!win.find(str))
  20.       while(win.find(str, false, true))
  21.         n++;
  22.     else
  23.       n++;
  24.     // If not found in either direction, give message.
  25.     if (n == 0)
  26.       alert("Takve rijeci nema.");
  27.   }
  28.   if (IE4) {
  29.     txt = win.document.body.createTextRange();
  30.  
  31.     // Find the nth match from the top of the page.
  32.     for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
  33.       txt.moveStart("character", 1);
  34.       txt.moveEnd("textedit");
  35.     }
  36.     // If found, mark it and scroll it into view.
  37.     if (found) {
  38.       txt.moveStart("character", -1);
  39.       txt.findText(str);
  40.       txt.select();
  41.       txt.scrollIntoView();
  42.       n++;
  43.     }
  44.     // Otherwise, start over at the top of the page and find first match.
  45.     else {
  46.       if (n > 0) {
  47.         n = 0;
  48.         findInPage(str);
  49.       }
  50.       // Not found anywhere, give message.
  51.       else
  52.         alert("Takve rijeci nema.");
  53.     }
  54.   }
  55.   return false;
  56. }
  57. </script>
  58. <form name="search" onSubmit="return findInPage(this.string.value);">
  59. <font size=3><input name="string" type="text" size=15 onChange="n = 0;"></font>
  60. <input type="submit" value="Find">
  61. </form>

Podrška samo putem foruma, jer samo tako i ostali imaju koristi od toga.