Thursday, 27 December 2012

IE7 and contentEditable

IE7 and contentEditable

Interestingly (I'm playing it rather loose and free with the term 'interestingly' here) I found that removing the contentEditable attribute from some elements cause them to become editable in IE7. The senario is this, HTML comes in, you don't know if it contains contentEditable attributes, but if it does you want to remove them. Run a function on the HTML to remove attributes. This was being done in jQuery.

$("*").removeAttr("contenteditable");

The effect of the above was some elements became editable in IE7, also list-items where missing their markers (common IE behaviour if contentEditable is true) running a function to set the attribute to false...

var els = document.getElementsByTagName("*");
for (var i = 0; i < els.length;i++){
    els[i].contentEditable = false;
}

... this will stop the content from being editable in IE7 but wouldn't fix the missing bullet markers. I still can't find a fix for this, so resorted to cleaning the HTML and stripping out the contentEditable attributes on the server before sending the HTML down to the client. (You can always rely on IE to give you something to do! : )

Also, interestingly *cough*, an embedded browser in a .NET app will use the oldest version of IE loaded on the machine, rather than the newest. So if your client is using IE9, it's still quite likely that they have something like IE7 in your .NET app. Worth setting the metadata X-UA-Compatible to IE=edge, this seems to have the effect to force the system to use the latest installed version of IE.

<meta http-equiv="X-UA-Compatible" content="IE=edge" />
As the above may cause validation errors, you might want to put this in your apache config instead...

Header set X-UA-Compatible "IE=edge"

Where ever you set this header, remember where it is, I have a nasty feeling it'll need editing at short notice at some point in the future!




No comments:

Post a Comment

 

Note: the opinions on this page don't represent that of my employer in anyway. And, actually only vaguely represent my opinions on the date of publication. (Unlike Ms T, I am very much for turning)