![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,537
|
Question for the HTML5 Brainiacs of GFY
Greetgins and salutations!
I have a question for the HTML5 gurus: How can I display a default image in HTML5 if the image I want is not available? Here's a piece of code: <div style="background-image: url(images20/intro.jpg);"> But in certain circumstances, the file named intro.jpg will not always exist. So when this file does not exist, I want it to load a different image. For example, default.jpg I can do this already with a standard IMG tag, like this: <img id="currentPhoto" src="intro.jpg" onerror="this.src='Default.jpg'"> But how do I do it when using a background image in a div?
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
<div style="background-image: url(images20/intro.jpg), url(default.jpg);">
That should use default.jpg as a fallback if the intro.jpg is not available. .
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,537
|
Thanks sarettah, but this doesn't seem to work for me
![]() Here's the full line: <div style="background-image: url(/images20/##Namevar##.jpg), url(/images20/default.jpg);"> (Namevar is dynamic. If the name doesn't exist, it should load default.jpg. but it dont dag nabbit!)
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Dec 2007
Location: Ontario
Posts: 4,235
|
why not bust one of these:
<div class="image-with-default" style="background-image: url(image.jpg)"> then in your CSS just add an image there as the default with the image-with-default class edit: no that wont work, i guess the first one would be overwritten, why not check if namevar exists and if it doesnt dont put in that line with the style stuff at all |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Quote:
Tried it in both chrome and firefox and both show the default image when the intro image is not there and show the intro image when it is there. Right now it should be showing the default.jpg because I renamed the intro.jpg to move it out of the way. Only difference in what code I am using is I have given a width and height attribute because otherwise it is an empty div without any size and won't show at all. I figured you probably had something in the div or had size attributes assigned in a style sheet, but I could be wrong about that. The code I have in there: Code:
<html> <head> <title></title> </head> <body> <div style="width:500px;height:500px;background-image: url(images20/intro.jpg), url(images20/default.jpg);"><div> </body> </html>
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Reworked it a few minutes ago using the exact same syntax you showed and it still works for me so I am guessing that you did not have any size attributes assigned to the div and it was empty so it did not show.
Code:
<html> <head> <title></title> </head> <body> <div style="width:500px;height:500px;background-image: url(images20/##Namevar##.jpg), url(images20/default.jpg);"><div> </body> </html>
__________________
All cookies cleared! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,537
|
Thanks! I will try it again.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,537
|
Hey Sarettah, thanks for your help! I got it to work. It originally wasn't working for me because my image variable had a space character in it.
So if image name = "ThisImage.jpg", then display it. if image name = "SomeOtherImage.jpg" then display default. if image name = "Some other Image.jpg" then display nothing, which was what it was doing. Thanks again!
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |