SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Find button???

  1. #1
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Find button???

    I'm looking for a script that works like the Ctrl-F function in MIE.

    I have a long list of names on a webpage, and instead of telling visitors to use the Ctrl-F function I would like to have a little button or link that basically does the same.

    Is this possible?

    Any help is appreciated

    Jazz...
    Last edited by jazztie; Nov 6, 2002 at 11:52.

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This example is, as you can see, working in Mozilla, NS4 & IE4+
    Code:
    <html>
      <head>
        <script language="javascript">
          function search(text)
          {
            if(!text) return false;
            var ua = navigator.userAgent;
            if(/Mozilla\/5\.0/.test(ua) && !/Netscape/.test(ua) || /Mozilla\/4/.test(ua) && !/MSIE/.test(ua))
            {
              find(text);
            }
            else if(/Mozilla\/4/.test(ua) && /MSIE/.test(ua))
            {
              var body = document.body.createTextRange();
              if(body.findText(text)) body.select();
            }
          }
        </script>
      </head>
      <body onload="search(prompt('Text to search for?', 'document'));">
        <p>Some text in the body of the document.</p>
      </body>
    </html>

  3. #3
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx Jofa,

    This works on the body onLoad command... but it doesn't seem to work on a 'a href' OnClick command:

    <a href="#" onClick="search(prompt('Text to search for?', 'document'));">search</a>

    or

    <a href="#" onClick="search(prompt('Text to search for?', ''));">search</a>

    am I missing something here?

    Jazz

  4. #4
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it also possible to 'highlight' all the words in the text that match the search-criteria?

    Or maybe, would it be possible to have a 'next' and 'previous' button to search for the next match?

    Jazz

  5. #5
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Re: Highlighting occurances of seach terms.

    It might be an idea to see how Google does it for their cached search results .

    Just an idea.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •