Capturing the output of a script src tag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ebobnar

    #1

    Capturing the output of a script src tag

    I'm sure you all have seen how using the src argument in a script tag
    is essentially the same as including the body of the script within
    your page. For example:

    <script type="text/javascript"
    src="http://somepage.com/somead/show_ads.js">
    </script>

    Is there a way to capture the html output of that script and save it
    to a variable or text file so that I can use a language like php to
    parse it and look for certain words or phrases?

    For instance, this particular url executes some javascript code which
    produces an iframe on my page, but view source only displays the
    script tag. Using innerHTML I can get the iframe code to print in
    another browser window, but I would prefer the iframe html be save to
    a variable or text file so that I can write a script to parse it on
    the fly.

    Please let me know if I'm being unclear and I'll try rephrasing my
    problem.

    Thanks a lot

    ebobnar
  • Brian Kerrick Nickel

    #2
    Re: Capturing the output of a script src tag

    This is a beautiful trick that works in lots of languages, you steal
    control of the writing function:

    <script type="text/javascript">
    var write_output = "";
    var document_write = document.write;
    document.write = function( )
    {
    for( var i = 0; i < arguments.lengt h; i ++ )
    write_output += arguments[ i ].toString( );
    };
    </script>
    <script type="text/javascript" src="look_at_me _I'm_an_ad.js"> </script>
    <script type="text/javascript">
    document.write = document_write;
    // Now you can read write_output
    </script>

    Have fun and good luck socking it to the crappy-ad-writing man.


    ..Brian

    Comment

    Working...