login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Zoeken op de pagina in Google Chrome

Offline DWolkier - 05/12/2009 14:17 (laatste wijziging 05/12/2009 16:28)
Avatar van DWolkierLid Beste leden,

Ik heb een klein scriptje gevonden waarmee ik gemakkelijk zou kunnen zoeken naar woorden op een pagina, maar deze lijkt niet te werken in Google Chrome. Hoe komt dit?

In de HEAD:

  1. <script language="JavaScript">
  2.  
  3. var NS4 = (document.layers); // Which browser?
  4. var IE4 = (document.all);
  5.  
  6. var win = window; // window to search.
  7. var n = 0;
  8.  
  9. function findInPage(str) {
  10.  
  11. var txt, i, found;
  12.  
  13. if (str == "")
  14. return false;
  15.  
  16. // Find next occurance of the given string on the page, wrap around to the
  17. // start of the page if necessary.
  18.  
  19. if (NS4) {
  20.  
  21. // Look for match starting at the current point. If not found, rewind
  22. // back to the first match.
  23.  
  24. if (!win.find(str))
  25. while(win.find(str, false, true))
  26. n++;
  27. else
  28. n++;
  29.  
  30. // If not found in either direction, give message.
  31.  
  32. if (n == 0)
  33. alert("Not found.");
  34. }
  35.  
  36. if (IE4) {
  37. txt = win.document.body.createTextRange();
  38.  
  39. // Find the nth match from the top of the page.
  40.  
  41. for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
  42. txt.moveStart("character", 1);
  43. txt.moveEnd("textedit");
  44. }
  45.  
  46. // If found, mark it and scroll it into view.
  47.  
  48. if (found) {
  49. txt.moveStart("character", -1);
  50. txt.findText(str);
  51. txt.select();
  52. txt.scrollIntoView();
  53. n++;
  54. }
  55.  
  56. // Otherwise, start over at the top of the page and find first match.
  57.  
  58. else {
  59. if (n > 0) {
  60. n = 0;
  61. findInPage(str);
  62. }
  63.  
  64. // Not found anywhere, give message.
  65.  
  66. else
  67. alert("Not found.");
  68. }
  69. }
  70.  
  71. return false;
  72. }
  73.  
  74. </script>


Iin de BODY:

  1. <form name="search" onSubmit="return findInPage(this.string.value);">
  2. <font size=3><input name="string" type="text" size=15 onChange="n = 0;"></font>
  3. <input type="submit" value="Find">

Martijn schreef:
Codetags!

1 antwoord

Gesponsorde links
Offline your_mother - 05/12/2009 14:24
Avatar van your_mother Nieuw lid Steffan en Nephilim voelen de glazenbol grap weer aankomen...
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.163s