Click to See Complete Forum and Search --> : Search Current Page
DJTheBaron
07-21-2008, 06:46 AM
Hello, I need some advice on searching a page for a keyword.
Im dealing with simply creating a few lists in html on an internal network for basic users to flick through remotley. They run the default internet explorer install that comes with xp, not updated and installing updates or firefox is not an option.
Im aware that typing ctrl+f in the browser will do just this for me, however im working with a framed page and the frame in question must be selected to perform the search. For example user clicks left frame menu to load main page content, they have not yet selected the main page and type ctrl+f to search and it only searches the selected menu frame not the main page.
I would like to have a search box at the top of the main page that searches the current page for keywords entered but dont know how.
Any ideas?
ray326
07-21-2008, 02:31 PM
Install a local search engine.
slaughters
07-21-2008, 02:43 PM
Try this:
http://www.google.com/sitesearch/
ray326
07-21-2008, 02:59 PM
Google sitesearch only works for sites exposed to the Internet.
slaughters
07-21-2008, 03:37 PM
OK - some simple googling turns up
"How to highlight search results with JavaScript and CSS" - http://eriwen.com/javascript/highlight-search-results-with-js/
donatello
07-21-2008, 04:04 PM
I used a javascript page search, but it's a bit quirky. I used it on this page: www.kantor.pl (http://www.kantor.pl/warszawa_en.php)
Here's the code:
<!--Search Box Script Begins-->
<script>
<!-- Hide from old browsers
/******************************************
* Find In Page Script -- Submitted/revised by Alan Koontz (alankoontz@REMOVETHISyahoo.com)
* Visit Dynamic Drive (http://www.dynamicdrive.com/) for full source code
* This notice must stay intact for use
******************************************/
// revised by Alan Koontz -- May 2003
var TRange = null;
var dupeRange = null;
var TestRange = null;
var win = null;
// SELECTED BROWSER SNIFFER COMPONENTS DOCUMENTED AT
// http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var nom = navigator.appName.toLowerCase();
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie = (agt.indexOf("msie") != -1);
var is_ie4up = (is_ie && (is_major >= 4));
var is_not_moz = (agt.indexOf('netscape')!=-1)
var is_nav = (nom.indexOf('netscape')!=-1);
var is_nav4 = (is_nav && (is_major == 4));
var is_mac = (agt.indexOf("mac")!=-1);
var is_gecko = (agt.indexOf('gecko') != -1);
var is_opera = (agt.indexOf("opera") != -1);
// GECKO REVISION
var is_rev=0
if (is_gecko) {
temp = agt.split("rv:")
is_rev = parseFloat(temp[1])
}
// USE THE FOLLOWING VARIABLE TO CONFIGURE FRAMES TO SEARCH
// (SELF OR CHILD FRAME)
// If you want to search another frame, change from "self" to
// the name of the target frame:
// e.g., var frametosearch = 'main'
//var frametosearch = 'main';
var frametosearch = self;
function search(whichform, whichframe) {
// TEST FOR IE5 FOR MAC (NO DOCUMENTATION)
if (is_ie4up && is_mac) return;
// TEST FOR NAV 6 (NO DOCUMENTATION)
if (is_gecko && (is_rev <1)) return;
// TEST FOR Opera (NO DOCUMENTATION)
if (is_opera) return;
// INITIALIZATIONS FOR FIND-IN-PAGE SEARCHES
if(whichform.findthis.value!=null && whichform.findthis.value!='') {
str = whichform.findthis.value;
win = whichframe;
var frameval=false;
if(win!=self)
{
frameval=true; // this will enable Nav7 to search child frame
win = parent.frames[whichframe];
}
}
else return; // i.e., no search string was entered
var strFound;
// NAVIGATOR 4 SPECIFIC CODE
if(is_nav4 && (is_minor < 5)) {
strFound=win.find(str); // case insensitive, forward search by default
// There are 3 arguments available:
// searchString: type string and it's the item to be searched
// caseSensitive: boolean -- is search case sensitive?
// backwards: boolean --should we also search backwards?
// strFound=win.find(str, false, false) is the explicit
// version of the above
// The Mac version of Nav4 has wrapAround, but
// cannot be specified in JS
}
// NAVIGATOR 7 and Mozilla rev 1+ SPECIFIC CODE (WILL NOT WORK WITH NAVIGATOR 6)
if (is_gecko && (is_rev >= 1)) {
if(frameval!=false) win.focus(); // force search in specified child frame
strFound=win.find(str, false, false, true, false, frameval, false);
// The following statement enables reversion of focus
// back to the search box after each search event
// allowing the user to press the ENTER key instead
// of clicking the search button to continue search.
// Note: tends to be buggy in Mozilla as of 1.3.1
// (see www.mozilla.org) so is excluded from users
// of that browser.
if (is_not_moz) whichform.findthis.focus();
// There are 7 arguments available:
// searchString: type string and it's the item to be searched
// caseSensitive: boolean -- is search case sensitive?
// backwards: boolean --should we also search backwards?
// wrapAround: boolean -- should we wrap the search?
// wholeWord: boolean: should we search only for whole words
// searchInFrames: boolean -- should we search in frames?
// showDialog: boolean -- should we show the Find Dialog?
}
if (is_ie4up) {
// EXPLORER-SPECIFIC CODE revised 5/21/03
if (TRange!=null) {
TestRange=win.document.body.createTextRange();
if (dupeRange.inRange(TestRange)) {
TRange.collapse(false);
strFound=TRange.findText(str);
if (strFound) {
//the following line added by Mike and Susan Keenan, 7 June 2003
win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop;
TRange.select();
}
}
else {
TRange=win.document.body.createTextRange();
TRange.collapse(false);
strFound=TRange.findText(str);
if (strFound) {
//the following line added by Mike and Susan Keenan, 7 June 2003
win.document.body.scrollTop = TRange.offsetTop;
TRange.select();
}
}
}
if (TRange==null || strFound==0) {
TRange=win.document.body.createTextRange();
dupeRange = TRange.duplicate();
strFound=TRange.findText(str);
if (strFound) {
//the following line added by Mike and Susan Keenan, 7 June 2003
win.document.body.scrollTop = TRange.offsetTop;
TRange.select();
}
}
}
if (!strFound) alert ("String '"+str+"' not found!") // string not found
}
// -->
</script>
<!-- EXAMPLE FORM OF FIND-IN-PAGE SEARCH USING SUBMIT (ALLOWING 'ENTER/RETURN' KEY PRESS EVENT) -->
<form name="form1" onSubmit="search(document.form1, frametosearch); return false"><input type="text" name="findthis" size="15" title="Press 'ALT s' after clicking submit to repeatedly search page"> <input type="submit" value="Szukaj" ACCESSKEY="s"></form>
<!--Search Box Script Ends-->
ray326
07-21-2008, 08:11 PM
Has anyone read the bit about frames?
DJTheBaron
07-22-2008, 04:28 AM
I used a javascript page search, but it's a bit quirky. I used it on this page: www.kantor.pl (http://www.kantor.pl/warszawa_en.php)
Here's the code:
This script does not work properly on your page, unless i select the page itself and click search it seems to be a ctrl+f feature that doesnt work in your frames.
DJTheBaron
07-22-2008, 04:34 AM
Install a local search engine.
When you say install a local search engine, you mean to search the entire site?
Basicially I have a frames page, the user selects a category from the menu and it appears in the main window, i onyl want to search the main window that the customer is currently browsing (ctrl+f) style, not search the entire site. I was hopting there was a script to slap a search box into the top of every category page so it ctrl+f its way down the selected page, similar to the kantor.pl post, except on that site even though i typed "kantor" into the box and submitted, it only searched the top right corner and not the body in the main page.
I know that the work around to my problem is have people click on the main page then type ctrl+f, and I have those instructions on the splash page, but anyone whos ever worked in an office will know that not everyone can perform a simple task such as this and need it further simplified, that and its more professional to have an intergrated soloution instead of a a workaround with pictures and instructions.
donatello
07-22-2008, 08:38 AM
Has anyone read the bit about frames?
What?
You actually expected us to read it thoroughly when we could shoot off a quick answer and be all wrong!!! :D
All kidding aside, I'm not sure if my script could be adapted to work in frames - I'm a rank amateur who has had a long lucky streak.
ray326
07-22-2008, 09:53 PM
What you're seeing is the reason the pros use includes rather than frames.
slaughters
07-22-2008, 10:37 PM
Pros use includes when server side languages are an option.