faqts : Computers : Programming : Languages : JavaScript : Images

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 1 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

How Can I Make A Complete Image Viewer (With No Bug) ?

Jan 20th, 2007 13:38
Abolfazl Shirazi,


Abolfazl Shirazi:
Once again nobody answer my question and at last I find my 
answer after a few month. This script first check the existence of the 
file using ActiveX and 
after that put it in IMG Tag and check it wheter the file is an image 
or not. 
Just try it :
<!-- Begin -->
<html>
	<head>
		<title>Untitled Page</title>
<script language="javascript">
function show() {
	fso = new ActiveXObject("Scripting.FileSystemObject")
	if (fso.FileExists(pathfield.value)) {
		imgfield.src = pathfield.value
		imgfield.onerror = notimage
		imgfield.onload = isimage
	}
	else {
		alert("The File doesnot exist")
		return false
	}
}
function ClearImg() {
	imgfield.onload = null
	imgfield.onerror = null
	imgfield.style.display = "none"
	imgfield.src = ""
}
function notimage() {
	alert("the file is not an image")
	return false
}
function isimage() {
	imgfield.style.display = "block"
	return true
}
</script>
	</head>
	<body bgcolor="#ffffff">
	<input type="file" name="pathfield"><br>
	<button onclick="show()">Show</button><button onclick="ClearImg
()">Clear Image</button>
	<p>
	<img name="imgfield" style="display:none">
	</body>
</html>
<!-- End -->
It works successfully in IE6, but I don't try it in netscape or others.