...

View Full Version : Find in Page Help



glengates
09-14-2010, 08:34 PM
Hi Folks!
Im a total newbie trying to teach myself as I go.....so any help that can be provided would be greatly appreciated!!

I am using the below script - find in page that seaches iframe - but need some help.
This script returns:

1. Searches for whole word only
2. Finds only the first matching entry

What I really want it to do is:

1. Searches for partial words or words containing the text I am searching for
2. Finds the first entry, and on pressing again finds the second and so on

Can anyone tell me how/where I change the below coding to achieve this?

Any help would be greatly appreciated....Thank You.
Glen

[CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Alternate Numbers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
form {
margin:0;
padding:0;
}
table {
border:1px solid #000;
margin:auto;
}
td {
border:1px solid #000;
border-collapse:collapse;
}
h1 {
font-size:19px;
font-weight:bold;
margin:0;
padding:0 0 15px 0;
text-align:center;
}
p {
margin:0;
padding:0;
}
-->
</style>
<script type="text/javascript">
<!-- 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-deve...wser_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 = 'altFrame';


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, true, true, true);

// 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,0,2);
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,0,2);
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,0,2);
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 ("No numbers for '"+str+"' Location") // string not found


}
// -->
</script>
</head>
<body>
<h1>Budget Counter Alternate Numbers </h1>
<form action="#" name="form1" onSubmit="search(document.form1, frametosearch); return false">
<table style="width:574px;" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width:568px;height:33px;background:#CCC;"><p class="style1">Alternate Number Search</p> Enter Location Code:
<input name="findthis" type="text" title="Press 'ALT s' after clicking submit to repeatedly search page" size="20" maxlength="20">
<input type="submit" value="Search" ACCESSKEY="s">
</td>
</tr>
<tr>
<td style="height:25px;background:#FFF;"><iframe src="Error Code Website Final.htm" width="860" height="450" name="altFrame" scrolling="yes " frameborder="0"></iframe></td>
</tr>
</table>
</form>
</body>
</html>
[CODE]

Spudhead
09-15-2010, 03:20 PM
That code was last revised in 2003, and looks like it was first written some considerable time before that. If your code was written for a version of IE that's 13 years old: do yourself a favour and ditch it.

For example, there's a Jquery (http://jquery.com/) plugin (http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html) that does pretty much all the heavy lifting for you:



<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highlight search</title>

<style type="text/css">
.highlight { background-color: yellow }
</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.highlight-3.js"></script>

<script type="text/javascript">
$(function(){
$('#mybutton').click(function(){
$('p').highlight($('#searchtext').val());
});
});
</script>

</head>

<body>
<input type="text" id="searchtext" value="ipsum"><button id="mybutton">Find it</button>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque euismod nunc vel pede. Nulla sapien purus, dictum quis, consectetuer sed, laoreet vel, ipsum. Pellentesque suscipit vulputate lorem. Cras sed lacus. Nullam pellentesque magna at quam. Fusce faucibus ligula sed urna. Morbi consectetuer dignissim urna. Nulla facilisi. Nulla tincidunt nunc ornare mauris. Aliquam massa. Proin vitae turpis in dui fringilla cursus. Nunc gravida dolor nec mauris. Aenean vehicula. Etiam lacinia urna convallis dui. Maecenas fermentum cursus nunc.</p>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum