/    Sign up×
Community /Pin to ProfileBookmark

I have a script that displays images in a directory, when it tries to call an image that doesnt exist it replaces the image with ‘NoImage.gif’ which is a 1×1 clear pixel.

I can’t help but feel I am doing this shotty. Is there a way to just have not display anything onerror?

[CODE]document.writeln(‘<img src =”‘ + strURL +
‘” onError=”this.src=’NoImage.gif’;” border=”0″>’);[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Arty_EffemNov 13.2007 — I have a script that displays images in a directory, when it tries to call an image that doesnt exist it replaces the image with 'NoImage.gif' which is a 1x1 clear pixel.

I can't help but feel I am doing this shotty. Is there a way to just have not display anything onerror?

[CODE]document.writeln('<img src ="' + strURL +
'" onError="this.src='NoImage.gif';" border="0">');[/CODE]
[/QUOTE]
You could try hiding the placeholder:[CODE]document.writeln('<img src ="' + strURL +
'" onerror="this.style.visibility='hidden'" border="0">');[/CODE]

To prevent the page layout distorting, you may want to specify width and height.

Whenever you do try to load an alternative image, the first statement in the onerror handler should be:[CODE]this.onerror=null;[/CODE]
×

Success!

Help @rabit spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...