The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

HTML Kludgin': Client-side code for selective tag generation?

Hi, all.

I've come across an odd quandary in the new application that I'm supporting, and I'm having trouble wrapping my brain around it.

I need to selectively add an <IMG> tag to a web page as its being generated, based on the results of checking for a file on the client's machine.  In my imagination, the code would look something like this:

<script>
function checkExists(String fileName)
{
  File tempFile = new File (fileName);
  if (fileName != null)
    return true;
  else
    return false; 
}
</script>

<script>
if checkExists("file:///c:/Images/special.jpg")
  Document.write('<IMG SRC=\"file:///c:/Images/special.jpg\">');
</script>

Now, I know that JavaScript's security model does not allow for checking a client's file system structure, hence the reason for this code only existing in my imagination.

Ladies and gentlemen, is there a way to make this a reality?

Thanks for the help,
Andy

P.S.: You're probably wondering why I'm looking for client-side images, and not storing them on a server, where I have a world of server-side scripting languages at my disposal.  I'm wondering the same!
Andy Nonymous Send private email
Wednesday, July 25, 2007
 
 
What you want to do isn't a good idea, browsers try to prevent remote sites getting any knowledge of what's on your hard drive for security purposes. An method you do find may well be patched at some point in the future as a security fix.

For example at http://www.xdisclose.com/XD100099.txt I found something that supposedly worked for some versions of IE (but fails in the current version, and Firefox):

<img src="file:///C:/test.jpg" onload="alert('loading image success')" onerror="alert('loading image error')">

I think the best you can do without using a browser plugin is to leave the broken image icon there when the image is not found.
Adam
Thursday, July 26, 2007
 
 
Is your HTML file local or on a server?  If it's on a server, you're out of luck.  You can't load local images from a remote file in newer browser versions at all -- let alone check for their existence.  If it's local, you can load the image and then use one of the various size properties (clientWidth, clientHeight, for example) to see if it sized to your image or the missing image symbol.  This is a huge hack but it seems like whatever you're doing is a huge hack anyway!
SomeBody Send private email
Friday, July 27, 2007
 
 
Use AJAX ... write a php script that does the checking.
Then use AJAX to add your img tag as needed.
anonymous_coward
Friday, July 27, 2007
 
 
I won.  This idea is dead.

Thanks for the advice, but reason prevailed (which is remarkable!).

Regards,
A.N.
Andy Nonymous Send private email
Friday, July 27, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz