javascript - anyway to check that a img tag is broken or 404'd; without add'l network request -
i using casperjs scrape items, can't on page enough add load , error events on img tags. prefer not have new xhr request each image determine it's validity.
is there way select image tag , determine if there image there or if not in alt text displayed? js only, after page loaded.
this not duplicate. asking if there way without network request. other questions have answers require creating new image new source , network request.
/ edit
specifically looking asserting if image loaded after complete (document.queryselector('#myimage').complete // returns true
:
- no new network request (includes creating new image new source)
- no onload/onerror events (requires doing before page loaded)
- assert
#myimage
broken without above
i don't know how use , here code snippet w3schools.
<!doctype html> <html> <body> <p>this example uses html dom assign "onerror" event img element.</p> <img id="myimg" src="image.gif"> <p id="demo"></p> <script> document.getelementbyid("myimg").onerror = function() {myfunction()}; function myfunction() { document.getelementbyid("demo").innerhtml = "the image not loaded."; } </script> </body> </html>
Comments
Post a Comment