이미지 태그 어트리뷰트

이미지 태그

<img>

를 javascript로 동적 생성했을때 IE에서 나타나는 문제

image.width = 50;
image.height = 50;
image.src = 'url_of_image.png';
var image = new Image();

 

어떤 특정한 경우에 이렇게 하면 IE의 경우에선 url_of_image의 width, height값으로 attribute가 변경되어 버린다.

 

안전하게 하기 위해서는

var image = new Image();
image.onload = function(e) {
    var e = e || window.event;
    var t = e.target || e.srcElement;
    t.width = 50;
    t.height = 50;
}
image.src = 'url_of_image.png';

 

 

 

2009/04/16 17:51 2009/04/16 17:51
juniac
javascript 2009/04/16 17:51

트랙백 주소 : http://juniac.net/trackback/187

댓글을 달아 주세요

[로그인][오픈아이디란?]

Powerd by Textcube, designed by criuce