なぜポップアップ警告は、「のdesignModeを」影響を与えることができますか?

StackOverflow https://stackoverflow.com/questions/741343

質問

私は、ページエディタを構築するためにexpreimentingました。 1つの問題は、単に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」を設定するapproprateであるかどうかを確認してください。ページのロード時に、「Mozillaは、」ポップアップ表示します。 iframeのエリアをクリックして、フォーカスがIFRAMEの上にあると私はキーボードで入力することができます。

このは正常に見えるが、私はラインの の「警告( "モジラ")をコメントアウトするとき、の」、それは仕事をdoesntの。 「のdesignModeは」放火犯が示すように「オフ」です。

これはとても有線です。なぜアラートがDOMとJavaScriptに影響を与えることができますか? ところで、私のFirefoxは3.0.6です。

役に立ちましたか?

解決

アラートは、ロードするiframeの時間を与えるので。

:あなたはへのiframeドキュメントがロードされた後にのみ「オン」のdesignModeを設定する必要があります
iframe.onload = function() {
    doc.designMode = "on";
};
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top