2010-04-21 3 views
0

iframe의 요소를 포함하여 문서의 모든 head 요소에 style 요소를 추가하려고합니다. 내가iframe을 포함한 문서의 모든 head 요소 검색

var heads = document.getElementsByTagName('head'); 

를 사용하는 경우

은 단지 첫 번째 머리 요소와있는 iframe이 아닌 사람을 반환합니다. 이 전체 코드입니다 :

var heads = document.getElementsByTagName("head"); 
var style = document.createElement("style"); 
style.type = "text/css"; 
style.appendChild(document.createTextNode(css)); 
for(var i=0;i<heads.length;i++) heads[i].appendChild(style); 

하지만이 작동하지 않는 것! 내가 여기서 뭔가 잘못하고있는거야 ...?

답변

0

이것은 나를 위해 일한 것입니다. 고맙습니다 모든 도움 btw -_-

try { if(top.location.href != window.location.href) { return; } } 
catch(e) { return; } 

window.setTimeout(getAllHeads, 1000); 

function getAllHeads() { 
    var heads = new Array(); 
    var head = document.getElementsByTagName("head")[0]; 
    if(head) addHead(head); 
    var frames = document.getElementsByTagName("iframe"); 
    for(var i = 0, len = frames.length; i < len; i++) { 
     var frame = frames[i]; 
     head = (frame.contentDocument).getElementsByTagName("head")[0]; 
     if(head) addHead(head); 
    } 

    function addHead(h) { heads.push(h); } 

    alert(heads.length); 
} 
1

당신이 getElementsbyTagName('iframe') 인 경우 어린이 요소를 가져 오시겠습니까?

크로스 사이트 스크립팅을 방지하기 위해 iframe에 대한 보안 제한 사항에 유의해야합니다.

+0

하지만 그게 iframe 헤드 요소를 줄 것입니다. 여기서는 iframe의 요소뿐만 아니라 모든 머리 요소를 얻고 싶습니다. – 1nfected

+0

범프, 누구든지 제발 ...? – 1nfected

관련 문제