A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.
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:
function checkExists(String fileName)
File tempFile = new File (fileName);
if (fileName != null)
Ladies and gentlemen, is there a way to make this a reality?
Thanks for the help,
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!
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.
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!
Use AJAX ... write a php script that does the checking.
Then use AJAX to add your img tag as needed.
Friday, July 27, 2007
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz