문제

나는 페이지 편집기를 만들기 위해 실험을 하고 있었습니다.한 가지 문제가 나를 Firefox에 미치게 만들었습니다.

페이지 코드는 아래와 같습니다.

<body>
<iframe WIDTH=200 HEIGHT=200 id="myEditor"></iframe>
<script>

    function getIFrameDocument(sID){
        // if contentDocument exists, W3C compliant (Mozilla)
        if (document.getElementById(sID).contentDocument){
            alert("mozilla"); // comment out this line and it doesn't work
            return document.getElementById(sID).contentDocument;
        } else {
            // IE
            alert("IE");
            //return document.getElementById(sID);
            return document.frames[sID].document;
        }
    }

    getIFrameDocument("myEditor").designMode = "On";

</script>

</body>

Mozilla 방식이나 IE 방식으로 "designMode"를 설정하는 것이 적절한지 확인하기만 하면 됩니다.페이지가 로드되면 "Mozilla" 팝업이 나타납니다.iframe 영역을 클릭하면 iframe에 포커스가 맞춰지고 키보드로 입력할 수 있습니다.

괜찮아 보이지만 해당 줄을 주석 처리하면 “alert("모질라");”, 작동하지 않습니다.FireBug가 보여주는 것처럼 "designMode"는 "Off"입니다.

이것은 너무 유선적입니다.경고가 DOM 및 JavaScript에 영향을 미칠 수 있는 이유는 무엇입니까?그런데 내 Firefox는 3.0.6입니다.

도움이 되었습니까?

해결책

경고는 iframe을 로드할 시간을 제공하기 때문입니다.iframe 문서가 로드된 후에만 designMode를 "on"으로 설정해야 합니다.

iframe.onload = function() {
    doc.designMode = "on";
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top