Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

img tag using innerhtml

Status
Not open for further replies.

NFI

Programmer
Jun 7, 2000
278
GB
Hello,

I've written a function which enumerates all the images in a folder and then shows them on a web page, using the innerhtml function. The code goes like this:

Code:
function draw_gallery(galPath){
  var fso;
  var fldr;
  var sHTML = "";
  //alert(galPath);
  fso = new ActiveXObject("Scripting.FileSystemObject");
  fldr = fso.GetFolder(galPath);
  eFiles = new Enumerator(fldr.Files);
  for (;!eFiles.atEnd();eFiles.moveNext())
  {
    sHTML += "<img src='" + galPath + eFiles.item().name + "' alt='" + eFiles.item().name + "'><br>";
  } 
  alert(sHTML);
  document.getElementById('gallery').innerHTML = sHTML;
}

This is then called in the onload event of the pages body tag, but for some reason, the images don't show. Instead, I just get a load of placeholders. The path is fine - it's definitely finding the images properly, my browser just won't show them. If I bring up the right click properties of any of the images, all the options (address etc) are "Not Available". I'm using IE7 under Vista and I've put this site in my trusted sites, so I'm pretty sure it's not a security problem.

Has anybody got any ideas?

Thanks,

NFI
 
Does the path have a space or other odd character in it that would need escaping?

Perhaps converting the local path to a file:// protocol URL might work?

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi Dan,

thanks for that, but the path is fine. The function finds the images with no problems; to make sure, I put in the alt= part to return the file names and they're all as they should be.

Beats me :(

NFI
 
Hi

Could you post what the [tt]alert(sHTML)[/tt] shows ?

( I do not know Explorer, but you may prefer to do [tt]prompt('',sHTML)[/tt] to be able to copy & paste it more simply. )

Feherke.
 
[1] If it is on a trust site with a big "T", rename the file from .html to .hta. It will then show you the norm of the rendering.

[2] This will make it less dependent on the hazard of having the trailing backslash in the path to fold.
>sHTML += "<img src='" + galPath + eFiles.item().name + "' alt='" + eFiles.item().name + "'><br>";
[tt]sHTML += "<img src='" [red]+ eFiles.item().path +[/red] "' alt='" + eFiles.item().name + "'><br>";[/tt]
 
Hello,

thanks for yor help.

I thought this was just an IE weirdism, as I restarted my machine and the images all worked. Today, though, I've booted again and they've gone back to just being place-holders :(

Here's what sHTML returns;

Code:
<img src='c:\inetpub\[URL unfurl="true"]wwwroot\shetland\gallery\engine_out\P8160028.JPG'[/URL] height=60 width=80 style="position='absolute';left='10';top='40'"><img src='c:\inetpub\[URL unfurl="true"]wwwroot\shetland\gallery\engine_out\P8160029.JPG'[/URL] height=60 width=80 style="position='absolute';left='100';top='40'"><img src='c:\inetpub\[URL unfurl="true"]wwwroot\shetland\gallery\engine_out\P8160030.JPG'[/URL] height=60 width=80 style="position='absolute';left='190';top='40'"><img src='c:\inetpub\[URL unfurl="true"]wwwroot\shetland\gallery\engine_out\P8160031.JPG'[/URL] height=60 width=80 style="position='absolute';left='280';top='40'"><img src='c:\inetpub\[URL unfurl="true"]wwwroot\shetland\gallery\engine_out\P8160032.JPG'[/URL] height=60 width=80 style="position='absolute';left='370';top='40'"><img src='c:\inetpub\[URL unfurl="true"]wwwroot\shetland\gallery\engine_out\P8160033.JPG'[/URL] height=60 width=80 style="position='absolute';left='460';top='40'"><img src='c:\inetpub\[URL unfurl="true"]wwwroot\shetland\gallery\engine_out\P8160034.JPG'[/URL] height=60 width=80 style="position='absolute';left='10';top='110'"><img src='c:\inetpub\[URL unfurl="true"]wwwroot\shetland\gallery\engine_out\P8160035.JPG'[/URL] height=60 width=80 style="position='absolute';left='100';top='110'">

I've added a bit to my function to chuck in the style code (to space the images properly), but that's not what's broken this...

I've just tried clearing my internet cache et al, restarting my browser half a dozen times and going back through all the IE security settings, but with no luck so far. I would try putting my page through FireFox to see if it's just IE making a hash of it, but not showing the images is as nothing compared to the balls-up FF makes of my CSS!

I've been trying to figure out the path to the images, too. At the moment, I can only get my function to work if I pass the FSO the absolute path to the images folder (i.e. c:\inetpub\ - if I try and pass it anything else (e.g. shetland\gallery\engine_out\ or .\shetland\gallery\engine_out or I get a "path not found" error. Can the FSO deal with URL paths?

I'm going to try rebooting the machine again (nothing like grasping at straws!) and, if that works, I'm going to assume it's sun-spots and call in a witch-doctor :(

Any more thoughts will be much appreciated,

Thanks,

NFI
 
Hi

Your [tt]style[/tt] tag is a mess :
[ul]
[li]separate the property and the value with colon ( : )[/li]
[li]do not enclose the value in single quotes ( ' )[/li]
[li]specify the unit of measurement for lengths[/li]
[/ul]
Code:
<img src='[red]/[/red]shetland[red]/[/red]gallery[red]/[/red]engine_out[red]/[/red]P8160028.JPG' height=60 width=80 style="position[red]:[/red]absolute;left[red]:[/red]10[red]px[/red];top[red]:[/red]40[red]px[/red]">

Feherke.
 
[3] >Can the FSO deal with URL paths?
No. And that is not negotiable.

[4] If the directory is on the server, you do thing server-side, and in that case, knowing half-side (only client-side) of the story is not enough. Complaining ie won't help. Furthermore, ff can access local file system but certainly not through fso you're using - only most fans wouldn't care to study before criticising - so it is pointless to use the present script on ff.

[5] I am not going to repeat myself anymore: if you want to know the client-side behaviour, it is hta as mentioned in [1].
 
Hello,

Thanks feherke - my style tags are a mess :) It's been a good year since I wrote any CSS and I was sort of guessing the syntax :)

tsuji, I can see my lack of knowledge in this area has upset you, and for that I apologise. I can see now that my problem is the mix of server and client side actions my script is attempting to do - the confusion betwen the path styles (absolute for the FSO and URL for the innerHTML) is, I fear, insurmountable. I would imagine I am going to have to do some of this in php to get it to work at the client end. Many apologies for manoeuvring you into the unfortunate position of having to repeat yourself, but I tried converting my page to .hta and I really couldn't see what the benefit was.

Many thanks for your help,

NFI
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top