/    Sign up×
Community /Pin to ProfileBookmark

browser determine

hello,
i have a problem with my web page’s search engine. the search is in the web page and i wan’t it to be compatible with any browser, especially mozilla. is there any javascript that i can add?
i have a javascript on the top where specifies whether the browser is ie or netscape and the search engine works just fine. when i open my page in mozilla browser the search engine isn’t working..
i would appreciate any help,
thanks. 😮

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesDec 07.2006 — If you want it compatable with [i]any[/i] browser, and you should, then you can't use JavaScript for this. You have to use some sort of server side script.
Copy linkTweet thisAlerts:
@chrystaauthorDec 08.2006 — the page is in php and i have added the code below witch works in ie and netscape.

<script language="JavaScript">

// Determine browser.

var IE4 = (document.all);

var win = this; // Page 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 (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", i);

}

// If found, mark it and scroll it into view.

if (found) {

txt.findText(str);

txt.select();

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>

can't i add anything else to the code to be compatible to mozilla ?
×

Success!

Help @chrysta spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...