[thelist] JavaScript - Pull from another site and display....
Matt Warden
mwarden at gmail.com
Thu Oct 7 23:39:02 CDT 2004
Hello Mr. Ditty,
On Thu, 7 Oct 2004 22:27:23 -0500, Chris Ditty <cditty at gmail.com> wrote:
> I have someone that wants me to write a where someone can just copy a
Wait, write a what?
> piece of javascript and paste it onto their site. The javascript will
> grab some dynamic information from a site and will allow me to
> customize the output.
You can do this by creating a javascript file, full of
document.write()'s. Then the person on the remote site will just
reference your javascript file as if it were any normal external
javascript:
<script src="http://foo.com/asdflkj.js" type="text/javascript" />
3rd party banner advertisers use this method a lot. Obviously, you
could use dynamic script (like PHP) to create the js file. Then you
would want to do something like this:
<script src="http://foo.com/ext/asdflkj.php" type="text/javascript" />
Now, if you run into problems with the extension, use .htaccess to
forcetype all files in the ext directory as php, then rename the file
with a .js extension.
What you will likely run into is caching issues. If possible, you
would want to do something like this:
<script src="http://foo.com/ext/asdflkj.php?r=<?php echo $randomnum
?>" type="text/javascript" />
where $randomnum is a random number. This will create a unique URI and
hopefully that will avoid caching problems. Of course, this requires
that everyone that includes this on their page have php available AND
that the page is a PHP page. This probably defeats your purpose.
Anyone have any ideas of how to avoid caching issues without using
dynamic script? Obviously you could try using PHP to set no-cache and
expires headers, but YMMV with those.
--
Matt Warden
Miami University
Oxford, OH
http://mattwarden.com
This email proudly and graciously contributes to entropy.
More information about the thelist
mailing list