Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Would like a RegExp to insert a string

    I admit RegExp is dark land for me, but I would like if some1 helped me I got the following string.


    Code:
    <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.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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:
    Code:
    var
        oTemp,
        i=0;
    while((oTemp=document.getElementsByTagName('iframe').item(i++))
        oTemp.onload=function(e){
            e=e||window.event;
            /* your onload handler */
        }
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Din't seem to work sadly , here is my highly inteligent test code

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

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Are you passing an argument to your function? Where is the aHTML coming from?

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Originally posted by Garadon
    Din't seem to work sadly , here is my highly inteligent test code
    Code:
    <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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •