Yves-Alain NICOLLET wrote:
Yv*****************@bull.net (Yves-Alain NICOLLET) wrote in message
news:<72**************************@posting.google. com>...
Please do not write attribution novels.
I have a script that opens a small window containing a button
Note the security restrictions for the window size:
http://devedge.netscape.com/manuals/2000/javascript/1.3/reference/window.html#1202731>
[...] Now I want it to find the next occurence of one of
the words contained in a list, ie. I want to dynamically change the
string to find. I failed to use a regular expression instead of a
string in the find statement. Any idea of how I can do that? Thanks.
To make myself clearer, is there a way to say:
find(a_word OR another_word OR yet_another_word OR etc) ?
Depends. There is the proprietary window.find() method which
returns `true' if unsuccessful, `false' otherwise. So you can
do consecutive searches:
function findWords()
{
var t;
if ((t = typeof window.find) == "function"
|| (t == object && window.find != null))
{
for (var i = 0, len = arguments.length; i < len; i++)
{
var s = arguments[i];
if (window.find(s))
{
return true; // or s if you like
}
}
}
return false; // no match
}
if (!findWords("a_word", "another_word", "yet_another_word", "etc"))
{
alert("No match for either"
+ "'a_word', 'another_word', 'yet_another_word' or 'etc'");
}
If you want two or more words to be matched and to be selected at
the same time, you need to parse the documents content. Dirty
proprietary quickhack:
document.body.innerHTML.replace(
/(a_word|another_word|yet_another_word|etc)/g,
'<span style="background-color:yellow; color:black">$1</span>');
HTH
PointedEars