简体   繁体   中英

Can't switch on designMode in Internet Explorer

The following code works in Firefox 3.6, but not in Internet Explorer 8:

<html>
<head>
   <title>Example</title>
   <script type="text/javascript">
      function init() {
         alert(document.designMode);
         document.designMode = "on";
         alert(document.designMode);
      }
   </script>
</head>
<body onload="init()">
</body>
</html>

In FF the alerts show 'off', then 'on'; in IE they're both 'Off'.

What am I doing wrong?

尽管designMode是标准,但您可能会更好地使用IE中的contentEditable属性。

Even though this won't change what the alerts show, it will turn on an editable mode in IE:

<html>
<head>
   <title>Example</title>
   <script type="text/javascript">
      function init() {
         alert(document.designMode);
         document.designMode = "On";
         document.body.contentEditable = 'true';
         alert(document.designMode);
      }
   </script>
</head>
<body onload="init()">
</body>
</html>

You can test by placing some dummy content in the page body (like <p>Test</p> ) and loading in both FF and IE. It's a suitable workaround for at least IE8.

Internet Explorer 文档似乎表明designMode属性区分大小写,需要设置为"On" ,而不是"on"

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