window.find in IE

Hello,

I was wondering if there is a function that has the same result as window.find (in Netscape) in Internet Explorer? For some reason the window.find function does not work in Internet Explorer 5.0.. Thanks!

Ian
LVL 1
ianpughAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
kmartin7Connect With a Mentor Commented:
The following is set up to sork in a frameset, but can be configured to work w/o a frameset.  

It works 2 ways - 1) select a word in the second frame by drag-and-drop method, then click on "Find in the top frameset , or 2) First click on "Find" in the top frameset to launch a prompt in ehich to type in the search string.

Fset.htm:
<HTML>
<HEAD>
<TITLE>IE_Find</TITLE>
</HEAD>
      <FRAMESET ROWS="45, *">
            <FRAME SRC="find.htm" NAME="find">
            <FRAME SRC="text.htm" NAME="text">
      </FRAMESET>
</HTML>

find.htm:

<HTML>
<HEAD>
<TITLE>Find in IE</TITLE>
</HEAD>
<BODY BACKGROUND="" BGCOLOR="#ffffff" TEXT="#000000" LINK="#0000ff" VLINK="#800080" ALINK="#ff0000">
<CENTER>
<a href="javascript:FD983r={x:function(){
var%20r,i,s=parent.frames[1].document.selection.createRange().text;
      if(!s)s=prompt('Type in the string you are searching for:','');
            if(s){r=parent.frames[1].document.body.createTextRange();
            for(i=0;r.findText(s);i++){r.execCommand('BackColor','','#FF0080');
      r.collapse(false)};if (i==0){
            alert('The string \'' + s + '\' is not found in this document.');
}
      else{
            alert('There are ' + i + ' instances of the string: \''+s+'\'.')}}}
};
      FD983r.x();">Find</a>
</CENTER>
</BODY>
</HTML>

text.htm:
   
<html>
<head>
<title>Text</title>
</head>
<body>
<p>
This is a test find page (from E-E homepage).

Welcome to Experts Exchange, the Internet's largest network of qualified technology experts. EE offers its members fast, free answers to questions in over 80 computer technology categories.  
   
Windows 95  
General
Setup
Windows 98


Windows NT  
General
Setup
NT 5


Windows Etc.  
3.x General
3.x Setup
Office-Word-Excel
Outlook


Databases  
Access
Fox Pro
General
MS-SQL
Oracle
Sybase


Internet  
General
Newbies
Browsers
Hot URLs

 Computers  
General
Newbies
Year 2000
Games


PDA  
Palm Pilot
Windows CE


Groupware  
Lotus Notes


Hardware  
General
Modems
Printers
HP Printers
HP Scanners
Scanners


Macintosh  
Applications
Communications
System


 Programming  
C
C++
Delphi
Java
JavaScript
Macintosh
MFC
OWL
OS/2
Pascal
Perl
Unix
Windows
Visual Basic
VB Databases
VB Controls


WWW Dev.  
Front Page
Authoring
CGI
HTML
Images
XML
ASP
ColdFusion
PHP
 Unix  
General
Setup


Linux  
General
Setup


Networking  
Linux
Macintosh
NetWare
OS/2
Unix
Windows 95
Windows NT


OS/2  
Applications
General
Setup


Graphics  
Fonts
General
Photoshop


EE Support  
Experts Exchange

More topics...
</body>
</html>

If you need more help, let me know.

Kurt
0
 
ianpughAuthor Commented:
Adjusted points to 100
0
 
PBallCommented:
A workaround in IE...
possibly...TextRange object or
enclose your document in a DIV and you can use the DIV id and get the innerText/innerHTML property of it and find the string in there using String object search, indexOf, lastIndexOf methods or VBScript instr.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ianpughAuthor Commented:
Adjusted points to 200
0
 
giant_lizard_of_deathCommented:

bFound = oTextRange.findText(sText, [, iSearchScope] [, iFlags]);

oTextRange = object, the text range duh
sText      = text to be found
iSearchScope = #of chars to search from the starting point of oTextRange
iFlags     = (2 = match whole word)
             (4 = case sensitive)
   <i'm guessing iFlags is a bitfield>

Try this code fragment (shamelessly stolen from MSDN docs):

var oRange =
   document.body.createTextRange();

// record current position
var sBookmark = oRange.getBookmark();

// go to "foo"
oRange.findText('foo');

// go back to sBookmark
oRange.moveToBookmark(sBookmark);
0
 
ianpughAuthor Commented:
Adjusted points to 245
0
 
ianpughAuthor Commented:
It does not seem to work right!
0
 
ianpughAuthor Commented:
Thanks!
0
 
ianpughAuthor Commented:
Kurt--

Is there a way to clear the area before you do another search? So only the current criteria are highlited? Thanks!

Ian
0
All Courses

From novice to tech pro — start learning today.