Code Examples
  Home arrow Code Examples arrow Searching Body Text with textRange: Enter ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Searching Body Text with textRange: Enter the Gecko
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 39
    2005-07-07

    Table of Contents:
  • Searching Body Text with textRange: Enter the Gecko
  • The first function
  • The second function
  • Create a master script file

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Searching Body Text with textRange: Enter the Gecko


    (Page 1 of 4 )

    This article focuses on turning the IE only body-text searching JavaScript file from the previous article into something that is supported and works on browsers using the Gecko layout engine. The conversion is surprisingly simple, and due to the advanced window.find() method compatible with Gecko, the script is actually smaller, with fewer moving parts!

    Calling this article "Using the textRange Object to Search Body Text" is actually a bit of a misnomer, because there is no textRange object in the gecko DOM.  However, as the script provides the same function as the scripts in the previous articles, it follows on to a sensible conclusion to what has been discussed already.

    There is no textRange simply because one is not needed in browsers such as Mozilla, FireFox or Netscape. The find() method of the window object is advanced enough to be able to search through the text in the body of a document without even needing to capture the text using the textRange object. Ranges of any kind just don’t need to be used.

    The script used here was written by myself but inspired by a script created by Jason Karl Davis (http://www.jasonkarldavis.com/) that uses DOM treewalking methods to traverse the text nodes of the document and match search words against their contents. DOM scripting has not been used in this example at all, simply because the power provided by it is not required in a search script of the same scope as the one discussed in parts one and two.

    The script I will discuss has been tested on Mozilla 1.7.6 and 1.7.8, Firefox 1.0 and 1.0.4 and Netscape versions 7.2 and 8, and has been found to work as intended on all of them. To create a test version of this script, create a new js file. The variables can still be defined at the top of the file, but the range variable will not be needed:

    var searchWord

    var match

    var button1clicked

    More Code Examples Articles
    More By Dan Wellman


       · where is the actual javascript code?
       · hi, whats your email and I'll send you the source files directlyDan
     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek