On 09 Sep 2003 14:03:34 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
document.body.innerHTML =
document.body.innerHTML.replace(new RegExp(items.join("|"),""),"IGNORED");
Thx a bunch Lasse for the prompt answer :-) It looks like a much
better solution, although I'll still have to find out the following:
1. innerHTML only seems to work in IE. Doesn't work with Opera 5 and
might not work with Netscape
2. Only the first occurence of the pattern is replace, ie. if I have
(John|Jane), and those items both appear in the page, only the first
occurence is replaced (the second is ignored). I assume I need to add
/g somewhere to tell JS to search & replace _all_ occurences
3. I'm actually parsing rows in a table, so need to construct a more
complicated search pattern than the one I gave to get started. The
goal is to replace any row that contains any of the items into an
empty row (ie.
<tr><td> </td><td> </td><td> </td><td> </td></tr>).
FWIW, here's what I'd like to do:
---------
function clean() {
var items = new Array("John", "Jane");
document.body.innerHTML = document.body.innerHTML.replace(new
RegExp(items.join("|"),""),"IGNORED");
}
[...]
<body onload='clean()()'>
<table>
<tr>
<td bgcolor="#FFFFFF" ><a
href="forum.php?forum=myforum&m=123">Title</a></td>
<td bgcolor="#FFFFFF">John</td>
<td bgcolor="#FFFFFF">10</td>
<td bgcolor="#FFFFFF">Posted 13 sept</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" ><a
href="forum.php?forum=myforum&m=124">Title</a></td>
<td bgcolor="#FFFFFF">Jane</td>
<td bgcolor="#FFFFFF">2</td>
<td bgcolor="#FFFFFF">Posted 12 sept</td>
</tr>
</table>
---------
If you have any idea or sample code on the Net swhere, I'm interested
:-)
Thx again for your help
JD.