{"id":101,"date":"2010-01-25T00:42:28","date_gmt":"2010-01-25T00:42:28","guid":{"rendered":"http:\/\/barrycarlyon.co.uk\/wordpress\/?p=101"},"modified":"2010-01-25T01:48:33","modified_gmt":"2010-01-25T01:48:33","slug":"javascript-image-onload-broken","status":"publish","type":"post","link":"https:\/\/barrycarlyon.co.uk\/wordpress\/2010\/01\/25\/javascript-image-onload-broken\/","title":{"rendered":"Javascript Image.onLoad Broken"},"content":{"rendered":"<p>Heres my code:<\/p>\n<blockquote>\n<pre>\r\n        var target = '';\r\n        var loadstr = '';\r\n        var webcamimg = '';\r\n\r\n        function runwebcam(ttarget) {\r\n                target = ttarget;\r\n                webcamimg = new Image();\r\n                loadstr = \"http:\/\/lsrfm.com\/images\/webcam\/lsr_studio.jpg?\" + Math.random();\r\n                webcamimg.src = loadstr;\r\n                webcamimg.onLoad = gowebcam();\r\n        }\r\n\r\n        function gowebcam() {\r\n                \/\/stuff\r\n        }\r\n<\/pre>\n<\/blockquote>\n<p>Thru the use of <a href=\"http:\/\/getfirebug.com\/\">FireBug<\/a> I&#8217;ve discovered that the function onLoad declared by onLoad is executing regardless of whether the image has finished being downloaded, which was my understanding as per <a href=\"http:\/\/articles.techrepublic.com.com\/5100-10878_11-5214317.html\">TechRepublics Article<\/a>.<\/p>\n<p>So after a bit of hunting around I found this from <a href=\"http:\/\/talideon.com\/weblog\/2005\/02\/detecting-broken-images-js.cfm\">Talideon.com<\/a>.<\/p>\n<p>So my adjusted code now reads:<\/p>\n<blockquote>\n<pre>\r\n        function runwebcam(ttarget) {\r\n                target = ttarget;\r\n                webcamimg = new Image();\r\n                loadstr = \"http:\/\/lsrfm.com\/images\/webcam\/lsr_studio.jpg?\" + Math.random();\r\n                webcamimg.src = loadstr;\r\n                webcamimg.onLoad = gowebcam();\r\n        }\r\n        function gowebcam() {\r\n                if (!webcamimg.complete) {\r\n                        setTimeout(\"gowebcam()\", 500);\r\n                        return;\r\n                }\r\n                \/\/stuff\r\n        }\r\n<\/pre>\n<\/blockquote>\n<p><strong>Update:<\/strong><\/p>\n<p>Video of before\/showing the fucked-upness<\/p>\n<!--YouTube Error: bad URL entered-->\n<p>And Not fucked<\/p>\n<!--YouTube Error: bad URL entered-->\n","protected":false},"excerpt":{"rendered":"<p>A Javascript Problem, and a Solution<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[88,45],"tags":[90,89,36,37,91],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-code-geekery","category-geekery","tag-broken","tag-firebug","tag-geek","tag-javascript","tag-solution"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":0,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"wp:attachment":[{"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barrycarlyon.co.uk\/wordpress\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}