Capturing the output of a script src tag

E

ebobnar

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
 
B

Brian Kerrick Nickel

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.length; 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top