...

View Full Version : Would like a RegExp to insert a string



Garadon
02-02-2004, 05:36 PM
I admit RegExp is dark land for me, but I would like if some1 helped me I got the following string.




<TABLE cellspacing="0" cellpadding="0" border="0"><TR><TD colspan="3"><TABLE class="topBar" width="100%" cellspacing="0" cellpadding="0"><TR><TD class="drag"><B id="StandardHeader1">Test<\/b><\/td><td><IMG align="right" src="Graphic/window/close_o.gif" border="0" onClick="addWindow.hide();" onMouseOver="this.src=\'Graphic/window/close_ovr.gif\';" onMouseOut="this.src=\'Graphic/window/close_o.gif\';"><\/td><\/TR><\/TABLE><\/TD><\/TR><TR height="100%"><TD><TABLE class="HozSides" style="width:5px;height:100%"><TR><TD><\/TD><\/TR><\/TABLE><\/td><TD><IFRAME frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" width="150" height="150" name="StandardContent1" id="StandardContent1" allowtransparency="true"><\/IFRAME><\/TD><TD><TABLE class="HozSides" style="width:5px;height:100%"><TR><TD><\/TD><\/TR><\/TABLE><\/TD><\/TR><TR><TD colspan="3"><TABLE class="BottomSides" width="100%"><TR><TD class="BottomSides"><\/TD><\/TR><\/TABLE><\/TD><\/TR><\/TABLE>



and I would like a RegExp that finds the occurence of the Iframe tag an inserts an onload event in that tag.

liorean
02-02-2004, 07:19 PM
A RegExp? Sure, re=/(<iframe)/i;. Then you do [string HTMLCodeToDoTheReplacementIn].replace(re, '$1 onload="yourEvent" '); This isn't the best way to do it, however. Why don't you do it like this:
var
oTemp,
i=0;
while((oTemp=document.getElementsByTagName('iframe').item(i++))
oTemp.onload=function(e){
e=e||window.event;
/* your onload handler */
}

Garadon
02-02-2004, 08:01 PM
Din't seem to work sadly :(, here is my highly inteligent test code :D



<script>
function replace(aHTML)
{
re=/(<iframe)/i;
aHTML.replace(re, '$1 onload="'+this.window+'.show();"');
alert(aHTML);
}
replace('<TABLE cellspacing="0" cellpadding="0" border="0"><TR><TD colspan="3"><TABLE class="topBar" width="100%" cellspacing="0" cellpadding="0"><TR><TD class="drag"><B id="StandardHeader1">Test<\/b><\/td><td><IMG align="right" src="Graphic/window/close_o.gif" border="0" onClick="addWindow.hide();" onMouseOver="this.src=\'Graphic/window/close_ovr.gif\';" onMouseOut="this.src=\'Graphic/window/close_o.gif\';"><\/td><\/TR><\/TABLE><\/TD><\/TR><TR height="100%"><TD><TABLE class="HozSides" style="width:5px;height:100%"><TR><TD><\/TD><\/TR><\/TABLE><\/td><TD><IFRAME frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" width="150" height="150" name="StandardContent1" id="StandardContent1" allowtransparency="true"><\/IFRAME><\/TD><TD><TABLE class="HozSides" style="width:5px;height:100%"><TR><TD><\/TD><\/TR><\/TABLE><\/TD><\/TR><TR><TD colspan="3"><TABLE class="BottomSides" width="100%"><TR><TD class="BottomSides"><\/TD><\/TR><\/TABLE><\/TD><\/TR><\/TABLE>');
</script>

Antoniohawk
02-02-2004, 08:47 PM
Are you passing an argument to your function? Where is the aHTML coming from?

liorean
02-02-2004, 09:17 PM
Originally posted by Garadon
Din't seem to work sadly :(, here is my highly inteligent test code :D


<script>
function replace(aHTML)
{
re=/(<iframe)/i;
aHTML.replace(re, '$1 onload="'+this.window+'.show();"');
alert(aHTML);
} Oh, the replace method doesn't change the aHTML variable, it just returns the changed value. Besides, you have a logic error there. this.window will return a string "[object Window]" or something, not the actual window object.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum