javascript - What HTTP headers/responses trigger the "onerror" handler on a script tag? -
i'm inserting script tag dom (think jsonp):
var s = document.createelement('script'); s.src = "http://abc.com/js/j.js"; s.onerror = function() { alert("error loading script tag!"); }; document.getelementsbytagname('head')[0].appendchild(s); now, know 404 response abc.com script above trigger event... other headers/responses cause script tag throw error? i'd imagine varies little bit browser, if has sort of list helpful.
thanks!
4xx , 5xx should result in error - @ least defined error codes.
[edit] tested in fx 3.5 - that's correct statement.
here's test code if want test other browsers (quick , dirty...)
var codes = [100, 101, 102, 122, 200, 201, 202, 203, 204, 205, 206, 207, 226, 300, 301, 302, 303, 304, 305, 306, 307, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410], 411, 411, 412, 413,414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 444, 449, 450, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510 ]; $(codes).each(function() { var s = document.createelement('script'); s.src = "http://localhost/test.php?code="+this; var cd = this; s.onerror = function() { document.write(cd+',') }; document.getelementsbytagname('head')[0].appendchild(s); }); and php code:
<?php header('http/1.0 '.$_get['code'].' ok'); ?>
Comments
Post a Comment