Last active
January 22, 2016 16:39
-
-
Save jacopotarantino/f0fa514fe4633bec87c9 to your computer and use it in GitHub Desktop.
Make broken images not suck.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
(() => { | |
'use strict' | |
let styles = ` | |
.pretty-broken-image { | |
visibility: hidden; | |
position: relative; | |
} | |
.pretty-broken-image:after { | |
content: 'oops!'; | |
background: lightblue; | |
display: block; | |
position: absolute; | |
top: 0; | |
left: 0; | |
height: 100%; | |
width: 100%; | |
visibility: visible; | |
color: white; | |
text-align: center; | |
line-height: 40px; | |
} | |
` | |
let stylesheet = document.createElement('style') | |
stylesheet.innerHTML = styles | |
document.body.appendChild(stylesheet) | |
})() | |
</script> | |
<img src="foobar-broken-link.gif" alt="i shouldn't load and this should have ugliness" onerror="this.classList.add('pretty-broken-image')"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment