2012-05-08 2 views
0

내 프로젝트 중 하나에서 Codemirror를 사용하고 있습니다. 다음 코드 : 나는 또한 제프리 방법을 사용하고Codemirror 및 iFrame 문제

<script> 
window.onload = function() { 
var te = document.getElementById("js"); 
var te_html = document.getElementById("html"); 
var te_css = document.getElementById("css"); 

window.editor = CodeMirror.fromTextArea(te, { 
mode: "javascript", 
    lineWrapping: true, 
    }); 

window.editor_css = CodeMirror.fromTextArea(te_css, { 
    mode: "css", 
    lineWrapping: true, 
    }); 

    window.editor_html = CodeMirror.fromTextArea(te_html, { 
    mode: "text/html", 
    lineWrapping: true, 
    }) 
}; 
</script> 

는 Tinkerbin, 또는 JSFiddle 비슷한을 구축 스크립트 "방법은 iframe에 사용자 정의 HTML과 CSS를 주입하는 방법"을 참조하십시오.

<script type="text/javascript"> 
(function() { 
    $('.grid').height($(window).height());  

    var contents = $('iframe').contents(), 
    body = contents.find('body'), 
    styleTag = $('<style></style>').appendTo(contents.find('head')); 

    $('textarea').keyup(function() { 
     var $this = $(this); 
     if ($this.attr('id') === 'html') 
     { 
     body.html($this.val()); 
     } 
     else 
     { 
     styleTag.html($this.val()); 
     } 

    }); 

})(); 
</script> 

그것은 아무것도 결과 탭에 활성화 된 CodeMirror 스크립트를 것을 제외하고, 모든 벌금 보여줍니다 것 :

여기에 그 부분에 대한 내 코드입니다. CodeMirror 코드 부분을 삭제하면 제대로 작동합니다.

http://mediodesign.ca/cms-test/

누구는 충돌이 어디 알고 :

여기 내 프로젝트 링크입니까?

감사합니다.

답변

0

은 당신이 XHTML 파일 내부에이 스크립트를 사용하는 경우 모든 자바 스크립트

mode/javascript.js 
mode/css.js 
mode/xml.js 

를로드했는지 확인하십시오. 큰 따옴표 ( ") 대신 작은 따옴표 ( ')를 사용하십시오.

ex.

<script> 
window.onload = function() { 
var te = document.getElementById('js'); 
var te_html = document.getElementById('html'); 
var te_css = document.getElementById('css'); 

window.editor = CodeMirror.fromTextArea(te, { 
mode: 'javascript', 
    lineWrapping: true, 
    }); 

window.editor_css = CodeMirror.fromTextArea(te_css, { 
    mode: 'css', 
    lineWrapping: true, 
    }); 

    window.editor_html = CodeMirror.fromTextArea(te_html, { 
    mode: 'text/html', 
    lineWrapping: true, 
    }) 
}; 
</script> 

제프리 웨이의 어떻게 iframe이에 사용자 정의 HTML과 CSS를 주입합니다 ... codemirror 스크립트

로드의 무관