|
This javascript adds a button called "Find on This Page..." to your HTML document. When the button is pressed a pop-up window (DIV) comes on the HTML document and asks for the text to search for and then the user can press "Next" or "Prev" to search for all the occurrences of the search term. This is similar to asking your users to press CTRL+F. But lets face it, it is much nicer to have a button for finding on the page. In Netscape and Mozilla Firefox there is a built-in find function with it's own search window. So this Javascript just calls the function window.find() when the user presses the "Find on This Page..." button, if it detects Netscape or Firefox. In Internet Explorer we do not have the window.find() function so we have to create floating DIV for a search window. Then we use Internet Explorer's built-in functions for creating text ranges ( createTextRange() ) and for finding search terms in those ranges ( findText(string) ). The script also uses the getBookmark() function to save positions in the text range so the user can search forwards and backwards. Features
To use the script just right click on the file name and then click on "Save target as...". find.js Then in your HTML document paste the following code where you
want the "Find on this Page..." button to appear: Notes: Update: 9/18/07 You can still choose to use the built-in search window with this script by changing the variable mozilla_opt to 0. However certain versions of Netscape don't seem to find the search terms when you call the built-in search window with window.find(). For Firefox I had to add a few functions because Firefox
looses focus on the selection when you press the Next or Prev
buttons. So it could only find the first occurrence of the
search term over and over. So for firefox I had to add the
following functions to record the highlighted selection: Then I had to use the following functions to highlight
the recorded search term again after a button was pressed: There does not seem to be a find function for Safari, so this button does not work in Safari. If you know of a find function for Safari then please let me know. |
Back to www.seabreezecomputers.com
|
User Comments
|