{"id":975,"date":"2011-08-29T19:01:44","date_gmt":"2011-08-29T11:01:44","guid":{"rendered":"http:\/\/leegorous.net\/blog\/?p=975"},"modified":"2012-03-03T19:00:02","modified_gmt":"2012-03-03T11:00:02","slug":"image-size-bug-in-ie","status":"publish","type":"post","link":"http:\/\/leegorous.net\/blog\/2011\/08\/29\/image-size-bug-in-ie\/","title":{"rendered":"IE \u4e2d\u56fe\u7247\u5927\u5c0f\u7684\u8bef\u5224"},"content":{"rendered":"<p>IE8 \u4ee5\u4e0b\u7684\u6d4f\u89c8\u5668\u90fd\u4f1a\u51fa\u73b0\u8fd9\u4e2a\u95ee\u9898\uff0c\u4e0d\u81f4\u547d\uff0c\u4f46\u975e\u5e38\u5f71\u54cd\u9875\u9762\u89c2\u611f\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u4f60\u4e0d\u4e00\u5b9a\u80fd\u9047\u4e0a\u3002<\/p>\n<p>\u60c5\u666f\u662f\uff0c\u56fe\u7247\u9700\u8981\u52a8\u6001\u52a0\u8f7d\uff0c\u6839\u636e\u7ed9\u51fa\u7684\u7f29\u653e\u6bd4\u4f8b\u8c03\u6574\u663e\u793a\u5927\u5c0f\u3002\u56fe\u7247\u662f\u666e\u901a PNG\uff0c\u53ea\u662f\u5b58\u653e\u70b9\u662f\u591a\u6837\u5316\u7684\uff0c\u540c\u6837\u7684\u56fe\u7247\uff0c\u4e00\u4e2a\u4ee5\u6587\u4ef6\u5f62\u5f0f\u5b58\u5728\uff0c\u53e6\u4e00\u4e2a\u662f\u4fdd\u5b58\u4e8e\u7f13\u5b58\uff08\u5185\u5b58\uff09\u4e2d\uff0c\u524d\u9762\u90fd\u662f\u7528 Apache\uff0c\u4e00\u4e2a\u8bfb\u6587\u4ef6\u8fd4\u56de\uff0c\u4e00\u4e2a\u505a\u8f6c\u53d1\uff0c\u7528 IE \u8bbf\u95ee\u5b83\u4eec\uff0c\u83b7\u53d6\u5176\u5927\u5c0f\u4fe1\u606f\uff0c\u7ed3\u679c\u7adf\u7136\u662f\u4e0d\u4e00\u6837\u7684\u3002<\/p>\n<p>\u88c5\u8f7d\u56fe\u7247\u7684\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<pre class=\"brush: js\">\r\nfunction loadImg(url, callback) {\r\n    var img = new Image();\r\n    img.src = url;\r\n    \r\n    if (img.complete) {\r\n        console.log(&quot;complete&quot;);\r\n        return callback.call(img, url);\r\n    }\r\n    img.onload = function() {\r\n        img.onload = null;\r\n        callback.call(img, url);\r\n    }\r\n    return img;\r\n}\r\n<\/pre>\n<p>\u8981\u5b8c\u6210\u7f29\u653e\uff0c\u9700\u8981\u83b7\u53d6\u56fe\u7247\u7684\u539f\u59cb\u5927\u5c0f\u3002\u5f53\u7136\u4e5f\u53ef\u4ee5\u7528\u767e\u5206\u6bd4\u6570\u503c\uff0c\u65b9\u6848\u6bd4\u8f83\u4e0d\u662f\u672c\u6587\u91cd\u70b9\u3002\u4e0b\u9762\u5199\u4e00\u4e2a\u51fd\u6570\u53ef\u4ee5\u6253\u5370\u51fa\u56fe\u50cf\u5bf9\u8c61\u4e0a\u6240\u6709\u7684\u6570\u503c\u5c5e\u6027\uff0c\u5f53\u7136\u5305\u62ec\u5bbd\u548c\u9ad8\u3002<\/p>\n<pre class=\"brush: js\">\r\nfunction getParam() {\r\n    var arr = [];\r\n    for(var i in this) {\r\n        try {\r\n            if (typeof this[i] !== &#039;number&#039;) continue;\r\n            arr.push(i + &#039; : &#039; + this[i] + &#039;\\n&#039;);\r\n        } catch(e) {} \/\/ this[i] \u5728 IE \u4e0b\u6709\u53ef\u80fd\u4f1a\u62a5\u9519\uff0c\u4e0d\u5f71\u54cd\u89c2\u5bdf\uff0c\u6682\u4e14\u5ffd\u7565\r\n    }\r\n    alert(arr.join(&#039;&#039;)); \/\/ \u4f7f\u7528 alert \u65b9\u4fbf\u89c2\u770b\u7ed3\u679c\r\n};\r\n<\/pre>\n<p>\u7136\u540e\u90fd\u6267\u884c\u4e0b\u9762\u7684\uff0c\u5176\u4e2d testPngURL \u5206\u522b\u4e3a\u4e24\u8005\u7684 URL\uff0c\u8fd9\u4e5f\u662f\u552f\u4e00\u7684\u533a\u522b\u4e86\u3002<\/p>\n<pre class=\"brush: js\">\r\npreload(testPngURL, getParam);\r\n<\/pre>\n<p>\u4e24\u6b21\u6267\u884c\u7684\u7ed3\u679c\u663e\u793a\u7684 width \u548c height \u662f\u4e0d\u4e00\u6837\u7684\uff0c\u800c\u4e14\u4e0d\u6210\u6bd4\u4f8b\uff0c\u800c\u4e14\u7ed3\u679c\u662f\u53ef\u4ee5\u7a33\u5b9a\u91cd\u590d\u7684\u3002\u6211\u6700\u7eb3\u95f7\u7684\u662f IE \u51ed\u4ec0\u4e48\u5f97\u51fa\u53e6\u5916\u90a3\u4e2a\u9519\u8bef\u7ed3\u679c\u7684\u3002\u6211\u521d\u65f6\u89c9\u5f97\u53ef\u80fd\u662f\u4e24\u6b21\u8bf7\u6c42\u7684 header \u4e0d\u4e00\u6837\uff0c\u4e3b\u8981\u5dee\u5f02\u662f\u5b58\u653e\u4e8e\u5185\u5b58\u7684\uff0c\u5176\u54cd\u5e94\u7684 Content-Type \u662f application\/octet-stream\uff0c\u6587\u4ef6\u5f62\u5f0f\u7684\u5219\u662f image\/png\uff0c\u5185\u5bb9\u957f\u5ea6\u662f\u5b8c\u5168\u4e00\u6837\u7684\u3002\u4e8e\u662f\u6211\u4f7f\u7528 Fiddler \u5bf9\u5185\u5b58\u56fe\u50cf\u7684\u8bf7\u6c42\u8fdb\u884c\u62e6\u622a\uff0c\u5e76\u4fee\u6539\u5176 Content-Type\uff0c\u7ed3\u679c\u662f\u65e0\u6548\u7684\u3002\u751a\u81f3\u5c06\u4e24\u8005\u7684\u54cd\u5e94\u5934\u5f04\u6210\u5b8c\u5168\u4e00\u81f4\uff0c\u4e5f\u5f97\u4e0d\u5230\u4e00\u81f4\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u6682\u65f6\u8fd8\u6ca1\u60f3\u5230\u6709\u4ec0\u4e48\u65b9\u6cd5\u53ef\u4ee5\u7ed5\u8fc7\u3002\u800c\u4e14\u6700\u5947\u602a\u7684\u662f\uff0c\u6709\u5c11\u6570\u51e0\u4e2a png \u7684\u5927\u5c0f\u662f\u6b63\u786e\u7684\u3002\u96be\u9053\u95ee\u9898\u51fa\u5728 png \u7684\u6570\u636e\u4e0a\uff0c\u6709\u4e9b\u9690\u85cf\u7684\u4fe1\u606f\uff0c\u4f46\u89e6\u53d1\u70b9\u5230\u5e95\u662f\u4ec0\u4e48\uff0c\u53ef\u662f\u6572\u7206\u5934\u4e5f\u4e0d\u77e5\u9053\u4e86\u3002<\/p>\n<p>\u867d\u7136\u751f\u4ea7\u4e0d\u4f1a\u8fd9\u4e48\u4f7f\u7528\uff0c\u4f46\u4e3a\u4e86\u5f00\u53d1\u8c03\u8bd5\u65b9\u4fbf\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528\u7f13\u5b58\u6765\u5b58\u653e\u5404\u79cd\u8d44\u6e90\uff0c\u5176\u8fd4\u56de\u5934\u90fd\u662f\u975e\u5e38\u7b80\u5355\u800c\u4e14\u7edf\u4e00\u7684\uff0c\u65e0\u4efb\u4f55\u591a\u4f59 header\uff0c\u6d4f\u89c8\u5668\u4e0d\u4f1a\u81ea\u4f5c\u4e3b\u5f20\u505a\u7f13\u5b58\u3002\u66f4\u65b0\u4e5f\u65b9\u4fbf\uff0c\u5f80\u540c\u4e00\u4e2a\u5730\u5740 PUT \u5185\u5bb9\u5373\u53ef\u3002\u73b0\u5728\u7531\u4e8e IE \u5b58\u5728\u8fd9\u6837\u4e00\u4e2a\u95ee\u9898\uff0c\u5176\u663e\u793a\u5927\u5c0f\u662f\u4e0d\u6b63\u786e\u7684\uff0c\u975e\u5e38\u5f71\u54cd\u89c2\u611f\uff0c\u4e0d\u5f97\u4e0d\u9700\u8981\u505a\u4e9b\u8c03\u6574\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>IE8 \u4ee5\u4e0b\u7684\u6d4f\u89c8\u5668\u90fd\u4f1a\u51fa\u73b0\u8fd9\u4e2a\u95ee\u9898\uff0c\u4e0d\u81f4\u547d\uff0c\u4f46\u975e\u5e38\u5f71\u54cd\u9875\u9762\u89c2\u611f\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u4f60\u4e0d\u4e00\u5b9a\u80fd\u9047\u4e0a\u3002 \u60c5\u666f\u662f\uff0c\u56fe\u7247\u9700\u8981 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/leegorous.net\/blog\/2011\/08\/29\/image-size-bug-in-ie\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cIE \u4e2d\u56fe\u7247\u5927\u5c0f\u7684\u8bef\u5224\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[57,62,8],"_links":{"self":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/975"}],"collection":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/comments?post=975"}],"version-history":[{"count":5,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/975\/revisions"}],"predecessor-version":[{"id":1051,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/975\/revisions\/1051"}],"wp:attachment":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/media?parent=975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/categories?post=975"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/tags?post=975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}