简体   繁体   中英

iframe designMode in firefox

I create iframe with designMode=on.

When I open web site in IE and move mouse cursor on iframe, the mouse cursor get changes into text-cursor (big letter I).

But when I open web site in Firefox, the corsur doesn't change and stays arrow-point cursor.

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 set in the call: document.getElementById(content).contentDocument.designMode = "on"; 在哪里:document.getElementById(content).contentDocument.designMode =“ on”;

Do you mean 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.

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

However, that won't get you a text caret in your IFrame, even if it does make it editable.

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.

You have to set this property when the iframe loads .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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