Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1778 Re: How do I check if an image file exists?

You are here: irt.org | FAQ | JavaScript | Image | Q1778 [ previous next ]

This might be useful for some. I needed to simulate an autorun script for users of our web interactive cd-rom product. This is one way to check if an image file exists (note: script not yet working in Netscape 6).

<html>
<head>
<title>Drive Letter Check</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<script language="JavaScript"><!--
var drive_letter = new Array();
drive_letter[0] = "E";
drive_letter[1] = "D";
drive_letter[2] = "C";
drive_letter[3] = "F";
drive_letter[4] = "G";
drive_letter[5] = "H";
drive_letter[6] = "I";
drive_letter[7] = "J";
drive_letter[8] = "K";
drive_letter[9] = "L";
drive_letter[10] = "M";
drive_letter[11] = "N";
drive_letter[12] = "O";
drive_letter[13] = "P";
drive_letter[14] = "Q";
drive_letter[15] = "R";
drive_letter[16] = "S";
drive_letter[17] = "T";
drive_letter[18] = "U";
drive_letter[19] = "V";
drive_letter[20] = "W";
drive_letter[21] = "X";
drive_letter[22] = "Y";
drive_letter[23] = "Z";
	
var loopcount = 0;
var path_start = "file:///";
var path_end = "|\\test.jpg";
var location_string = "http://www.mywebsite.com&DriveLetter=";
	
// Begin Array Loop
			
for (loopcount = 0; loopcount <= 23; loopcount ++) {
  var path_mid = drive_letter[loopcount];
  var URL = path_start + path_mid + path_end;
					
  // Print out images array
		
  document.write('<img src="'+URL+'">');
		
  // If image is defined (i.e. has dimensions of test image), got the drive letter!
		
  if ((document.images[loopcount].width == 3) && (document.images[loopcount].height == 2)) {
    // Now redirect user to welcome page with drive letter appended to URL string
    window.location.href=(location_string+path_mid);
  }

}
//--></script>
</body>
</html>

Submitted by Noah C

©2018 Martin Webb