2012-07-23 2 views
1
myIFrame = new IFrame({ 
    id: 'iframe_content', 
    src: '/iframe_src/' 
}); 
console.dir(myIFrame); 
var n = new Element('div', { 
    style: { 
     'width': '100px', 
     'height': "100px", 
     'border': '1px solid red' 
    } 
}); 

myIFrame.inject(document.body); 
console.log("innerhtml", myIFrame.contentDocument.body.innerHTML); 
console.dir(myIFrame.contentDocument.body); 
n.inject(myIFrame.contentDocument.body); 

div가 iframe에 삽입되지 않고 Ifrane의 요소에 액세스 할 수 없습니다. mootools 1.4.0 또는 MooTools 1.2에서 어떻게 할 수 있습니까?mootools에서 Iframe 콘텐츠 요소에 액세스하려면 어떻게해야합니까?

답변

3

콘텐츠가 혼합 된 콘텐츠 즉, src=의 콘텐츠와 추가 DOM 요소를 즉석에서 작성하면 다소 복잡합니다.

iframe에는 src 콘텐츠를 가져 왔을 때 발생하는 load 이벤트가 발생합니다.

http://jsfiddle.net/dimitar/AEP8T/

var myIFrame = new IFrame({ 
    id: 'iframe_content', 
    src: 'http://fiddle.jshell.net/_display/', 
    styles: { 
     width: 640, 
     height: 480 
    }, 
    events: { 
     load: function() { 

      var n = new Element('div', { 
       text: "hai there", 
       styles: { 
        'width': '100px', 
        'height': "100px", 
        'border': '1px solid red' 
       } 
      }); 

      n.inject(this.contentDocument.body); 

     } 
    } 
}).inject(document.body); 

SRC에와 포함 문맥

을 등 같은 도메인/포트 경우에만 동작합니다
관련 문제