Help Desk
By Ken Cox, guest Webmaster
Bandwidth Hogs
How can I use JavaScript to stop file leeches who link directly to a graphic on my site and use up my bandwidth? I haven't discovered any tricks to keep the browser from revealing the URL, although I have stopped it from appearing on the status bar of the source by using a JavaScript function to build the URL of the graphics. The graphics are viewed in a separate window, so it's difficult to allow that, yet stop direct linking from guest books and the like. Any ideas?
Louis
A server-side script would certainly help in this situation because it would let you store the images in a database. In doing so, you would have total control over the name of the file. You could even create a random filename for each image that only your script and database would recognize.
However, your question involves using JavaScript on the client. The problem with your situation is that as long as your own Web pages can find the files, other Web pages can do the same. If you want to make the files harder for other sites to decipher, you could try something like the following, which programmatically assigns the filename in a slightly convoluted format:
<html>
<body>
<img id="mypic" name="mypic" src="http://www.newarchitectmag.com/documents/s=4450/new1013636393/"></p>
<script language="javascript">
document.images[0].src="http://www.newarchitectmag.com/documents/s=4450/new1013636393/my" + "pic.gif";
document.images[0].width="114";
document.images[0].height="110";
</script>
</body>
</html>
Using a tool like Macromedia Fireworks 4 to slice a single image into several pieces is another approach to disguising your images.