On Fri, 23 Jun 2006 02:41:45 -0700, JohnSouth wrote:
Hi
I'm hoping to set up a system similar to Google Adwords that allows
other sites to extact a limited amount of data from my site, and
display it as part of their webpage. Google use a javascript file:
show_ads.js with parameters.
Can anyone explain how the .js file works? In particular how does it
output HTML back to the calling site, and how does it access the
parameters?
You can "fake" javascript file content. You write a cgi that returns valid
javascript and specify this as the source of the <script> tag eg (untested)
In html document:
....
<head>
<script type="text/javascript" language="JavaScript"
src="http:/www.yoursite.com/cgi-bin/js.pl"></script>
....
in js.pl:
#!/usr/bin/perl
use CGI qw(&header &cookie);
use strict;
use warnings;
my $cookie1 = cookie('cookie1');
print header('text/javascript');
print qq(var cookie1 = '$cookie1';);
Extending this idea, you can also have your "fake" javascript file return
html into valid javascript and place the script tag in your document body
at the place you want it printed eg.
<body>
....
<script type="text/javascript" language="JavaScript"
src="http:/www.yoursite.com/cgi-bin/js.pl"></script>
....
</body>
and in js.pl:
#!/usr/bin/perl
use CGI qw(&header);
use strict;
use warnings;
print header('text/javascript');
print <<EOT;
document.write('blah blah blah');
document.close();
EOT
HTH
Rich