2013-08-01 3 views
0

입니다. img 요소 만 포함하는 간단한 팝업 창에서 작업하고 있습니다. 모든 것이 잘 작동하지만 img 요소에 대한 클래스 선택기를 사용하는 데 문제가 발생했습니다. 문제는 IE8이 클래스 선택기를 사용하는 경우 팝업 내 img 요소에 스타일 (예 : 간단한 테두리)을 적용하지 않지만 은 id 선택기를 사용하는 경우 스타일을 적용한다는 것입니다. 내가 뭘 놓치고 있니? 다른 사람이 같은 결과를 얻고 있습니까? 티무는, 사용을 지적클래스 선택기는 IE8 팝업 창에서 작동하지 않지만 id 선택기는

자바 스크립트 ...

myWindow=window.open('','','width=450,height=800,scrollbars=yes,menubar=no,status=no,location=no,resizable=no,directories=no,toolbar=no'); 

// prepare pop-up window with basic html structure 
myWindow.document.open(); // maybe unnecessary 
myWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'); 
myWindow.document.write('<html><head><title>'+popupTitle+'</title>'); 
myWindow.document.write('<link rel="stylesheet" type="text/css" href="example.css"></script></head>'); 
myWindow.document.write('<body></body></html>'); 
myWindow.document.close(); // maybe unnecessary 

var imgdiv = myWindow.document.createElement('div'); 
imgdiv.setAttribute('id','popupwindowdiv'); 
myWindow.document.body.appendChild(imgdiv); 

// add image elements to the pop-up window 
for (var i=0; i < images.length; i++) { 
    var addImage = myWindow.document.createElement('img'); 
    addImage.setAttribute('src',<imgurl from images array>); 
    addImage.setAttribute('id','popupwindowimage'); // WILL WORK 
    //addImage.setAttribute('class','popupwindowimage'); // <-- WON'T WORK IN IE8 
    imgdiv.appendChild(addImage); 
} 
if (window.focus){ myWindow.focus(); } 

과 CSS를 ...

// works 
#popupwindowimage{ 
    border-style:solid; 
    border-width:1px; 
    margin-bottom:10px; 
} 
// doesn't work 
.popupwindowimage{ 
    border-style:solid; 
    border-width:1px; 
    margin-bottom:10px; 
} 
+0

'imgdiv.setAttribute ('id', 'popupwindowdiv');'클래스가 아닌 id를 설정하고 있습니다. – giaour

+2

'class' 속성 대신'className' 속성을 설정하십시오. Btw. 'document.close()'가 정말로 필요합니다. 브라우저가 항상 "busy"를 보여주지 않으면됩니다. – Teemu

답변

1

는 :

// add image elements to the pop-up window 
for (var i=0; i < images.length; i++) { 
    var addImage = myWindow.document.createElement('img'); 
    addImage.setAttribute('src',<imgurl from images array>); 
    //addImage.setAttribute('id','popupwindowimage'); // WILL WORK 
    //addImage.setAttribute('class','popupwindowimage'); // <-- WON'T WORK IN IE8 
    addItem.className += "popupwindowimage"; // <-- SHOULD WORK IN ALL BROWSERS 
    imgdiv.appendChild(addImage); 
} 

이를위한 최선의 선택이어야한다 당신.

+0

왜 당신이 + = 대신에 = =를 사용했는지 모르겠지만, 당신과 Teemu에게 감사드립니다. –