Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Find in page' script alternative 1

Status
Not open for further replies.
feherke

Thanks for your reply and link

Have also found this code at
Code:
<form name="f1" action="" 
onSubmit="if(this.t1.value!=null && this.t1.value!='')
findString(this.t1.value);return false"
>
<input type="text" name=t1 value="" size=20>
<input type="submit" name=b1 value="Find">
</form>

<script language="JavaScript">
<!--
var TRange=null

function findString (str) {
 if (parseInt(navigator.appVersion)<4) return;
 var strFound;
 if (window.find) {

  // CODE FOR BROWSERS THAT SUPPORT window.find

  strFound=self.find(str);
  if (!strFound) {
   strFound=self.find(str,0,1)
   while (self.find(str,0,1)) continue
  }
 }
 else 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()
  }
 }
 else if (navigator.appName=="Opera") {
  alert ("Opera browsers not supported, sorry...")
  return;
 }
 if (!strFound) alert ("String '"+str+"' not found!")
 return;
}
//-->
</script>
It works in IE, Safari and Chrome. It works in Firefox only if you click on the page below the form.

Any ideas as to how to force it to work in Firefox?


FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
It seems the problem with Firefox using the code posted is that by clicking on the page above the form, it searches and then the search stops at the form's textbox.

Clicking on the page below the form's textbox allows the search to continue to the end of the page.

So if the search could bypass the form's textbox, it might provide a solution.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Hi

Try to add this :
Code:
  // CODE FOR BROWSERS THAT SUPPORT window.find

  strFound=self.find(str);

  [red]if (strFound && !window.getSelection().anchorNode) strFound=self.find(str)[/red]

  if (!strFound) {
   strFound=self.find(str,0,1)
   while (self.find(str,0,1)) continue
  }

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top