简体   繁体   English

Firefox中的iframe designMode

[英]iframe designMode in firefox

I create iframe with designMode=on. 我使用designMode = on创建iframe。

When I open web site in IE and move mouse cursor on iframe, the mouse cursor get changes into text-cursor (big letter I). 当我在IE中打开网站并在iframe上移动鼠标光标时,鼠标光标会更改为文本光标(大写字母I)。

But when I open web site in Firefox, the corsur doesn't change and stays arrow-point cursor. 但是,当我在Firefox中打开网站时,corsur不会更改,而是保持箭头光标。

How to fix that? 如何解决?

 <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>

也许该页面会有所帮助?

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"

Question? 题? where is the variable content set in the call: document.getElementById(content).contentDocument.designMode = "on"; 在调用中设置的变量内容在哪里:document.getElementById(content).contentDocument.designMode =“ on”;

Do you mean editor as in: var edit = document.getElementById(editor).contentWindow.document; 您的意思是编辑器吗?var edit = document.getElementById(editor).contentWindow.document;

Okay, I see your problem, link to http://devedge-temp.mozilla.org/viewsource/2003/midas/01/example2-index.html has the same issue and that's the Mozilla way. 好的,我看到了您的问题,链接到http://devedge-temp.mozilla.org/viewsource/2003/midas/01/example2-index.html也是同样的问题,这就是Mozilla的方式。

Your line: 您的电话:

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

Should almost certainly read: 几乎应该阅读:

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

As it stands you're asking non-IE browser to find an element with id null , rather than an element with id 'content' . 就目前而言,您正在要求非IE浏览器查找ID为null的元素,而不是ID为'content'的元素。

However, that won't get you a text caret in your IFrame, even if it does make it editable. 但是,即使您将IFrame设为可编辑状态,也无法在IFrame中获得文字插入符号。

The best I could come up with was: 我能想到的最好的是:

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

Which turns the cursor into a caret on the first line of the iFrame (ie at the top), presumably because that's the only editable bit at that point. 它将光标变成iFrame 第一行 (即顶部) 上的插入符号,大概是因为那是那时唯一可编辑的位。

You have to set this property when the iframe loads . 当iframe loads时,您必须设置此属性。

var edit = document.getElementById(editor).contentWindow.document;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM