469,927 Members | 1,944 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

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
Jul 20 '05 #1
1 1915
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
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by jerrygarciuh | last post: by
4 posts views Thread by Mark Wilson CPU | last post: by
5 posts views Thread by Moosebumps | last post: by
2 posts views Thread by Ken Cox - Microsoft MVP | last post: by
6 posts views Thread by Ed Leafe | last post: by
1 post views Thread by Falcolas | last post: by
2 posts views Thread by gopala | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.