PDA

Click to See Complete Forum and Search --> : Wow


MattJH
Jan 16th, 2001, 10:06 AM
When you go to the "Edit" menu in Internet Explorer there is an option to 'Find (On this page) Ctrl + F'....Is there a way that I could possibly invoke this command by pressing a button on my web page (for instance).

All I need to do is search for a string on the current page.

I've tried

window.find();

And also the variant

window.find(variable);

niether work in IE5 but do in Netscape.

Please help.

Thanks in advance.

Matt.

sebs
Jan 18th, 2001, 07:38 AM
here's how to do it in javascript:


<script language="JavaScript"><!--
var pos = 0;
function findit() {
if (document.myform.mytext.value == '') {
alert('Nothing to search for');
return;
}
if (document.all) {
var found = false;
var text = document.body.createTextRange();
for (var i=0; i<=pos && (found=text.findText(document.myform.mytext.value)) != false; i++) {
text.moveStart("character", 1);
text.moveEnd("textedit");
}
if (found) {
text.moveStart("character", -1);
text.findText(document.myform.mytext.value);
text.select();
text.scrollIntoView();
pos++;
}
else {
pos=0;
text = document.body.createTextRange();
text.findText(document.myform.mytext.value);
text.select();
text.scrollIntoView();
}
}
else if (document.layers) {
find(document.myform.mytext.value,false);
}
}

if (document.layers || document.all) {
document.write('<form name="myform">');
document.write('<input type="text" name="mytext">');
document.write('<input type="button" value="Find" onClick="findit()">');
document.write('<\/form>');
}
//--></script>


hope it help

MattJH
Jan 22nd, 2001, 04:13 AM
Thanks for the information in your reply, it works really well, just another question though, how can I get it to search a different frame??


Cheers,


MattJH

sebs
Jan 22nd, 2001, 07:04 AM
instead of :

document.myform.mytext.value

use:


parent.frames.yourFrameName.document.myForm.mytext.value