Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

My javascript search engine doesn't work in Firefox

Featured Replies

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! :hello:

<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>


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?

  • Author

i'm such an (..) i was thinking about it this afternoon. still it bugs me that it doesn't work but ah well.

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.

  • 1 year later...

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 ?

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.