views:

128

answers:

3

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?

A: 

The Internet Explorer documentation seems to indicate that the designMode property is case-sensitive, and needs to be set to "On", not "on".

Syntactic
No, that didn't fix it. Incidentally, if I use a nonsense value like "xx", the assignment throws an exception, so my guess is that "on" and "On" are treated the same.
Charles Anderson
Well, it was worth a shot. I'd bet on EAMann's answer being a decent workaround.
Syntactic
I've actually read that support for the `designMode` property will eventually be dropped in favor of the `contentEditable` method. Apparently they function somewhat differently and cross-browser support for `contentEditable` is deeper than for `designMode`. Until the standards gurus make the official call, though, we should probably just develop with both in mind.
EAMann
+1  A: 

You may have better luck with the contentEditable attribute in IE, though designMode is the standard.

jimbojw
+1  A: 

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.

EAMann
contentEditable does the trick! (And the alerts were just there for debugging anyway.) TVM.
Charles Anderson