scanning javascrip result before displaying it

Discussion in 'JavaScript' started by hextraordinary, Apr 11, 2007.

  1. #1
    What I am trying to do it to skim through text received as a result of a javascript (and possible play around with it) before it is displayed on the page.

    I can't get my head around how it should be done.
     
    hextraordinary, Apr 11, 2007 IP
  2. Felu

    Felu Peon

    Messages:
    1,680
    Likes Received:
    124
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I might be able to help you if you can explain what exactly you want.
     
    Felu, Apr 11, 2007 IP
  3. hextraordinary

    hextraordinary Well-Known Member

    Messages:
    2,171
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    105
    #3
    well, i get an html (or any type of text for that matter) as a result from a javascript, what i want to do is scan that html page and look for specific keywords.

    The real issue is doing that prior to it being displayed on the page.
     
    hextraordinary, Apr 11, 2007 IP
  4. Felu

    Felu Peon

    Messages:
    1,680
    Likes Received:
    124
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just store the result in a variable and do the scanning, then display the page?
     
    Felu, Apr 11, 2007 IP
  5. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #5
    For example, to replace "orig" with "dest" only inside a "idKeywords" HTML tag, you can use something like this:
    
    <script type="text/javascript">
    
    function f_InnerEnId( p_id, p_toInner ) 
    { 
      try 
      { 
        document.getElementById( p_id ).innerHTML = p_toInner; 
      } catch(e) { } 
    }
    
    function f_getElement(p_id) 
    { 
      l_text=""; 
      try 
      { 
        l_elem=document.getElementById(p_id); 
        try 
        { 
          l_text+=l_elem.innerHTML; 
        } catch(e) { serializer1=new XMLSerializer(); l_text+=serializer1.serializeToString(l_elem); }; 
      } catch(e) { } 
      return l_text; 
    }
    
    var l_oldData = f_getElemento( "idKeywords" );
    var l_pattern = /(orig)/g;
    var l_newData = l_oldData.replace( l_pattern, 'dest' );
    f_InnerEnId( "idKeywords", l_newData ); 
    
    </script>
    
    Code (markup):
    And instead of "orig" and "dest" it will be better with your own regular expressions.
     
    ajsa52, Apr 11, 2007 IP