firefox中的iframe designMode

时间:2009-11-04 16:29:45

标签: asp.net javascript html

我使用designMode = on创建iframe。

当我在IE中打开网站并在iframe上移动鼠标光标时,鼠标光标变为文本光标(大字母I)。

但是当我在Firefox中打开网站时,corsur不会改变并保持箭头光标。

如何解决这个问题?

 <script language="javascript" type="text/javascript">
        designer('content');

        function designer(editor) {
            var browser = navigator.userAgent.toLowerCase();
            isIE = (browser.indexOf("msie") != -1);

            document.writeln('<iframe id="' + editor + '"  width="600px" height="600px"></iframe>');


            var edit = document.getElementById(editor).contentWindow.document;                                
            edit.designMode = "On";

            if (!isIE) {
                document.getElementById(content).contentDocument.designMode = "on";
            }
        }

    </script>

4 个答案:

答案 0 :(得分:1)

也许this page会有帮助吗?

答案 1 :(得分:0)

Try CSS, that should switch the cursor for you. 

iframe{cursor:crosshair} //all iframes on page
or
#content{cursor:crosshair} //just the element with the id "content"

的问题?调用中设置变量 content 的位置:document.getElementById(content).contentDocument.designMode =“on”;

你的意思是编辑,如:var edit = document.getElementById(editor).contentWindow.document;

好的,我看到了你的问题,链接到http://devedge-temp.mozilla.org/viewsource/2003/midas/01/example2-index.html有同样的问题,这就是Mozilla方式。

答案 2 :(得分:0)

你的专栏:

if (!isIE) {
  document.getElementById(content).contentDocument.designMode = "on";
}

几乎可以肯定地读到:

if (!isIE) {
  document.getElementById(editor).contentWindow.document = "on";
}

就目前而言,您要求非IE浏览器查找标识为null的元素,而不是标识为'content'的元素。

但是,即使它确实可以编辑,也不会在IFrame中显示文本插入符号。

我能想到的最好的是:

  document.getElementById(editor).contentWindow.document.style.cursor = "text";

将光标转换为iFrame第一行上的插入符号(即在顶部),大概是因为那是该点唯一可编辑的位。

答案 3 :(得分:0)

您必须在iframe loads

时设置此属性
var edit = document.getElementById(editor).contentWindow.document;

edit.addEventListener("load", function() {
    edit.designMode = "On";
}, false);