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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search field to local webpage

Status
Not open for further replies.

AndersonMarkus

Technical User
Oct 17, 2011
5
SE
Hi all,

I´ve found following JavaScript code on this page

<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 && !window.getSelection().anchorNode) 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>

The thing is that I have a webpage build on frames. The search code is places in a html document called clock.html and the information I want to search in is on a page called body.html.

Is it possible to change in code to search to another html document?
 
Hi

At first glance would be enough to replace [tt]self[/tt] with [tt]top.frames.name_of_your_other_frame[/tt].


Feherke.
 
Thanks for the reply.

I changed all self to top.frames.body (the frame is called body that I want to search from)

strFound=top.frames.body.find(str);
if (strFound && !window.getSelection().anchorNode) strFound=top.frames.body.find(str)
if (!strFound) {
strFound=top.frames.body.find(str,0,1)
while (top.frames.body.find(str,0,1)) continue

and

if (TRange==null || strFound==0) {
TRange=top.frames.body.document.body.createTextRange()
strFound=TRange.findText(str)
if (strFound) TRange.select()

But the clock frame (were the search field is placed is just flashing one time.
 
Hi

The first part of the code you posted above works for me in FireFox.

No idea about the Explorer-specific one, I have nothing to test with.


Feherke.
 
Hi again,

Strange since it doesn´t works for me.
How does you form looks like? Perhaps the issue is there.
 
Hi

Reduced them to the bare minimal, the body.htm is just some Lorem Ipsum :
Code:
[b]<html>[/b]
[b]<frameset[/b] [maroon]rows[/maroon][teal]=[/teal][green][i]"100,*"[/i][/green][b]>[/b]
[b]<frame[/b] [maroon]name[/maroon][teal]=[/teal][green][i]"clock"[/i][/green] [maroon]src[/maroon][teal]=[/teal][green][i]"clock.htm"[/i][/green][b]>[/b]
[b]<frame[/b] [maroon]name[/maroon][teal]=[/teal][green][i]"body"[/i][/green] [maroon]src[/maroon][teal]=[/teal][green][i]"body.htm"[/i][/green][b]>[/b]
[b]</frameset>[/b]
[b]</html>[/b]
Code:
[b]<html>[/b]
[b]<head>[/b]
[b]<script[/b] [maroon]src[/maroon][teal]=[/teal][green][i]"AndersonMarkus.js"[/i][/green][b]></script>[/b]
[b]</head>[/b]
[b]<body>[/b]
[b]<form[/b] [maroon]action[/maroon][teal]=[/teal][green][i]"#"[/i][/green] [maroon]onsubmit[/maroon][teal]=[/teal][green][i]"findString(what.value);return false"[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text"[/i][/green] [maroon]name[/maroon][teal]=[/teal][green][i]"what"[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"submit"[/i][/green][b]>[/b]
[b]</form>[/b]
[b]</body>[/b]
[b]</html>[/b]

Feherke.
 
I tested the code both i Fx and IE still won´t work :(
In Fx the browser freezes and in IE it just won´t search.
Weard.
 
Hi

By the way, my FireFox is version 7.0.1 on Linux.

As a note, although it works it is quite bad : finds each second occurrence. ( So skips one and finds the next, and so on. )

Personally I would not force such unportable, unreliable and ultimately useless script. Browsers have their own search facility and there are extensions to improve it. I see no reason to duplicate it.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top