Shoshoni Posted July 14, 2006 Posted July 14, 2006 OK I got this nice little script from a website somewhere. What it does, you enter a text string, press enter and then highlights the text. Very simple. I've searched high and low for how to get it to work in Firefox (I found some things but to no avail). From what I understand this script only supports ie4 and up and netscape.Here's the script. If someone has a solution I would be very grateful. Thanks in advance! <script language="JavaScript"><!-- More javascripts http://www.hypergurl.com -->var NS4 = (document.layers); // Which browser?var IE4 = (document.all);var win = window; // window to search.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("Not found."); } if (IE4) { txt = win.document.body.createTextRange(); // Find the nth match from the top of the page. for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); } // If found, mark it and scroll it into view. if (found) { txt.moveStart("character", -1); txt.findText(str); txt.select(); txt.scrollIntoView(); n++; } // Otherwise, start over at the top of the page and find first match. else { if (n > 0) { n = 0; findInPage(str); } // Not found anywhere, give message. else alert("Not found."); } } return false;}</script>
Chozo4 Posted July 16, 2006 Posted July 16, 2006 So your basically trying to recreate firefox's search method already?Also, did you also open firefoxes 'java console' (found in tools?) to see if any javascript errors had been reported back?
Shoshoni Posted July 18, 2006 Author Posted July 18, 2006 I noticed that the search script on the site i got it from http://www.hypergurl.com/searchpage.html doesn't work as well so that's one step ahead. Anyone ideas of how to make it FF compatible?
billybob bo buck Posted July 18, 2006 Posted July 18, 2006 didn't Chozo4 already tell you that firefox already has this feature, i mean what's the point?
Shoshoni Posted July 18, 2006 Author Posted July 18, 2006 i'm such an (..) i was thinking about it this afternoon. still it bugs me that it doesn't work but ah well.
Tomcat76 Posted July 22, 2006 Posted July 22, 2006 That's a really old script. The JavaScript sniffer stems from the Netscape 4 days...I'm not sure what the script is supposed to be doing but here's a version that should theoretically do it...<script type="text/javacript">var win = window; // window to search.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 (window.execScript) { txt = win.document.body.createTextRange(); // Find the nth match from the top of the page. for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); } // If found, mark it and scroll it into view. if (found) { txt.moveStart("character", -1); txt.findText(str); txt.select(); txt.scrollIntoView(); n++; } // Otherwise, start over at the top of the page and find first match. else { if (n > 0) { n = 0; findInPage(str); } // Not found anywhere, give message. else alert("Not found."); } } else { // 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("Not found."); } return false;}</script>@Chozo4... Java and JavaScript are two different things.
javeflorent Posted October 10, 2007 Posted October 10, 2007 Hi,@Tomcat76: really good it works with every internet browsers.Is there a way to perform such s "string search" in an iframe? The iFrame is located in the main page.So just a simple page with an iframe in it an the research is performed on the iframe content...I tried changing the window to search like this:---var win = window;win=parent.frames[myframe];---or---var win = window;win=document.getElementById('myframe').contentWindow;---I tried both but it does not work.Any other ideas ?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now