Forum Moderators: open

Message Too Old, No Replies

Displaying the MS Find function

How to call the MS Find function

         

Johnski

1:01 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Is it possible to open the MS Find funtion in IE via a button using JScript, rather than the usual method of pressing CTRL + F

jalarie

6:59 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



The following works in Netscape 4.x and 7.x, and in Firefox; it does not work in Internet Explorer nor Opera, nor does anything else that I've found:

<input type="button" value="Find in Page" onclick="javascript:find();" />

Sanenet

7:20 pm on Feb 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The following, stolen from javascript.internet.com, puts a search box on your page (works in IE, NN, FF):

<!-- TWO STEPS TO INSTALL FIND IN PAGE:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Mike Hall (MHall75819@aol.com) -->
<!-- Web Site: [members.aol.com...] -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source! [javascript.internet.com...] -->

<!-- Begin
var NS4 = (document.layers);
var IE4 = (document.all);

var win = this;
var n = 0;

function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0) alert(str + " was not found on this page.");
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str))!= false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert(str + " was not found on this page.");
}
}
return false;
}
// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<form name=search onSubmit="return findInPage(this.string.value);">
Find in Page
<input name=string type=text size=15 onChange="n = 0;">
</form>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 1.54 KB -->

Johnski

9:54 am on Feb 16, 2005 (gmt 0)

10+ Year Member



Thanks for the sarch code - Infact i'm already using this, but I need a way for the search to remain at the top of the page - i.e for the search to be in a frameset with the data in the lower frame and the search box to remain at the top. Unfortunately this script will only serach the page on which it is placed. I therefore am trying the route of either calling the MS Find function via a button (as that always remains on top of the page in view) or to put the search in a floating panel that scrolls down with the page.

Any ideas?

Many Thankks

Johnski

9:54 am on Feb 16, 2005 (gmt 0)

10+ Year Member



Thanks for the search code - Infact i'm already using this, but I need a way for the search to remain at the top of the page - i.e for the search to be in a frameset with the data in the lower frame and the search box to remain at the top. Unfortunately this script will only serach the page on which it is placed. I therefore am trying the route of either calling the MS Find function via a button (as that always remains on top of the page in view) or to put the search in a floating panel that scrolls down with the page.

Any ideas?

Many Thanks

Sanenet

1:17 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For a floating div or menu that always moves around the page, checkout the scripts at dynamicdrive.com.

It's all DHTML, but I think some of them work in O & FF.

Johnski

2:14 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



Thanks again - Right..I'm now making some progress and the hover ifame works a treat - but I now somehow need to make the Find function search a specified htm page in the dircetory rather than by default the one that the script is placed on. Is this possible? Cheers

Heres the script i've used:

<form name="f1" action=""
onSubmit="if(this.t1.value!=null && this.t1.value!='')
findString(this.t1.value);return false"
>
<div align="left">
<input type="text" name=t1 value="" size=15>
<input type="submit" name=b1 value="Find">
<script language="JavaScript">
<!--
var TRange=null

function findString (str) {
if (parseInt(navigator.appVersion)<4) return;
var strFound;
if (navigator.appName=="Netscape") {

// NAVIGATOR-SPECIFIC CODE

strFound=self.find(str);
if (!strFound) {
strFound=self.find(str,0,1)
while (self.find(str,0,1)) continue
}
}
if (navigator.appName.indexOf("Microsoft")!=-1) {

// EXPLORER-SPECIFIC CODE

if (TRange!=null) {
TRange.collapse(false)
strFound=TRange.findText(str)
if (strFound) TRange.select()
}
if (TRange==null ¦¦ strFound==0) {
TRange=self.document.body.createTextRange()
strFound=TRange.findText(str)
if (strFound) TRange.select()
}
}
if (!strFound) alert ("Sorry, the name '"+str+"' was not found in SWBU")
}
//-->
</script>