peterpeter2
Technical User
Hi,
I want to use a Find in Page script to let visitors search for text on a page. However, my pages are designed with Layers that are positioned at the same absolute location, all on top of each other. The script DOES find the text - even in hidden layers -, but I don't know how to show the the hidden Layer the text was found in. Can anyone please show me how to do that?
The Find in Page script code is as shown below.
An example of my page can be found at: http://test.vandervliet-online.com/1a_omgeving.html"][/URL] The various layers (containing an image and some text describing the image) are selected by clicking an image on the left side of the screen.
Thanks in advance for any help I can get.
Peter
I want to use a Find in Page script to let visitors search for text on a page. However, my pages are designed with Layers that are positioned at the same absolute location, all on top of each other. The script DOES find the text - even in hidden layers -, but I don't know how to show the the hidden Layer the text was found in. Can anyone please show me how to do that?
The Find in Page script code is as shown below.
Code:
var NS4 = (document.layers); // Which browser?
var IE4 = (document.all);
var win = window;
var n = 0;
function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
// Find next occurance of the given string on the page, wrap around to the
// start of the page if necessary.
if (NS4) {
// Look for match starting at the current point. If not found, rewind
// back to the first match.
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
// If not found in either direction, give message.
if (n == 0)
alert("Search text not found");
}
if (IE4) {
var range = win.document.body.createTextRange();
// Find the nth match from the top of the page.
for (i = 0; i <= n && (found = range.findText(str)) != false; i++) {
range.moveStart("character", 1);
range.moveEnd("textedit");
}
// If found, mark it and scroll it into view.
if (found) {
range.moveStart("character", -1);
range.findText(str);
range.select();
range.scrollIntoView();
n++;
}
// Otherwise, display message.
else {
if (n > 0) {
n = 0;
// findInPage(str);
alert("This was the last one.");
}
// Not found anywhere, give message.
else
alert("Search text not found");
}
}
return false;
}
An example of my page can be found at: http://test.vandervliet-online.com/1a_omgeving.html"][/URL] The various layers (containing an image and some text describing the image) are selected by clicking an image on the left side of the screen.
Thanks in advance for any help I can get.
Peter