Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Pesky red x (no img) boxes
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Pesky red x (no img) boxes

 Post Reply Post Reply Page  12>
Author
rocketdawg View Drop Down
Newbie
Newbie
Avatar

Joined: 03 August 2004
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote rocketdawg Quote  Post ReplyReply Direct Link To This Post Topic: Pesky red x (no img) boxes
    Posted: 10 January 2005 at 8:05pm
I have several thousand imgs in file. They are brand images corresponding to the product that my customer is looking at. Therefore, in the product description box I have this to call the appropriate image:
 
response.write "<img src=""imgs/" & strName & ".jpg"">"
 
Here is my question: Is there a way to substitute a smiley face, or a text string, instead of the pesky red x if no image is found in my file?
 
My wife is not liking my baldness from this. Any ideas anyone?
 
Thanks in advance.
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2005 at 10:23pm
It's a client-side browser issue. That particular red X only appears in IE. Other browsers use a different image for no image found.
 
With asp.net, you can set up an http handler to intercept image requests and serve up something special if they're not found.
With scripting languages and html however, the page returns a status of 200 - OK - so no way to use anything like a custom 404 page to deal with the image.
 
Your only alternative to something like .net is to use your own script to serve images - e.g. <image src="myscript.asp?imagename=xxx.jpg">
 
Your script could then use fso to get the image and response.writebinary to serve it up. If you get an fso error, then serve up the alternate image.
 
Note: response.binarywrite (objrs("Field_Name")  will display an image from a database record set pulled by an sql statement.


Edited by dpyers - 10 January 2005 at 10:39pm

Lead me not into temptation... I know the short cut, follow me.
Back to Top
rocketdawg View Drop Down
Newbie
Newbie
Avatar

Joined: 03 August 2004
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote rocketdawg Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2005 at 10:30pm

I understand that. My real question, better put, is:

Is there a way to write this:?

If (" & strName & ".jpg") = nuthin, then response.write("smiley.jpg")
 
The part I'm having trouble with is: If (" & strName & ".jpg") = nuthin
 
I am having trouble getting my page to recognize that there is no image in my image folder to response.write in the first place!
BTW, strName is a valid variable passed from the previous page.
 
Did that make more sense?
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 10 January 2005 at 10:41pm
I updated my previous post while you were posting, but what you'd need to do is use fso to see if the image exists or not,

Lead me not into temptation... I know the short cut, follow me.
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2005 at 12:43am
Try This...
<%
Function fncDoesFileExist(ByVal strFileName)
 dim objFSO
 dim strFilePath
 
 set objFSO= CreateObject("Scripting.FileSystemObject")
 
 strFilePath = Server.MapPath(strFileName)
 
 If objFSO.FileExists(strFilePath) then
     fncDoesFileExist = true
  else
     fncDoesFileExist = false
 End IF
 
 set objFSO= nothing
End Function
 
 
If fncDoesFileExist(strName & ".jpg") = true then
    response.write strName & ".jpg" 
    else
    response.write("smiley.jpg")
End IF

%>
 

Lead me not into temptation... I know the short cut, follow me.
Back to Top
Greyth View Drop Down
Newbie
Newbie


Joined: 21 May 2003
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote Greyth Quote  Post ReplyReply Direct Link To This Post Posted: 12 January 2005 at 7:06pm
Or you can use the same method that is used to get images using a BLOB field in a database and then make that the 404 error page for your image directory.

Since it is a 404 error, you would also probably want to add a line to reset the response status to whatever the header is for jpg.

That would basicly just save your page from having an extra hit on the hard drive and a little bit of code for regular loading. You could also have it send a variable through the querystring that you could use to track down products without images.

Check the article here:
http://support.microsoft.com/kb/173308/EN-US/


Edited by Greyth - 12 January 2005 at 7:40pm
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2005 at 10:19am
You can add a single line of javascript to the img tag that displays a different image if one isn't found.  Can't remeber where I saw it though, might want to look on google.
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2005 at 10:26am
onerror=this.SRC="image path to error image"

i believe thats it.

insert that within the image tag ie <img src="" onerror=this.src="">


Edited by dj air - 13 January 2005 at 10:27am
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.