Aphanasiy Posted February 3, 2006 Share Posted February 3, 2006 Hello folks, could you please explain to me why this script doesn't work? <span style="background-image:url('http://www.badimage.gif')" onerror="alert('testing')">test</span> Onerror is supposed to work when my browser downloads an image, if it can't find one the onerror function is fired. Why doesn't it work here when it works in this script? <img src="http://www.badimage.gif" onerror="alert('testing')"> Link to comment Share on other sites More sharing options...
aspnetguy Posted February 3, 2006 Share Posted February 3, 2006 Because the <span> does not have an error...the style attribute does if it doesn't load the background.Loading an image and loading a background image are different and obviously trigger events differently.AFAIK there is no way to catch an error when a bg doesn't load. Link to comment Share on other sites More sharing options...
Aphanasiy Posted February 3, 2006 Author Share Posted February 3, 2006 Thank you very much that helped. Link to comment Share on other sites More sharing options...
Aphanasiy Posted February 3, 2006 Author Share Posted February 3, 2006 Because the <span> does not have an error...the style attribute does if it doesn't load the background.Loading an image and loading a background image are different and obviously trigger events differently.AFAIK there is no way to catch an error when a bg doesn't load.<{POST_SNAPBACK}> So how do I trigger an onerror function using the style attribute please?Edit: Sorry for double post. Link to comment Share on other sites More sharing options...
aspnetguy Posted February 3, 2006 Share Posted February 3, 2006 I don't think you can Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now