SoFunction
Updated on 2025-02-28

CodeMirror2 IE7/IE8 The following unknown runtime error solution

The original error code is as follows:
Copy the codeThe code is as follows:

<p style="margin-top:0;">
<asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Height="450" Width="98%"></asp:TextBox>
</p>

The reason for the error should be that P in IE7 and IE8 does not support innerHTML. The author of CodeMirror also discovered this problem, related links:
/marijnh/CodeMirror2/issues/215
/marijnh/CodeMirror2/commit/4886415d6054571f92fa4d5601ebe7d601e952ab
Copy the codeThe code is as follows:

try { stringWidth("x"); }
catch (e) {
if ((/runtime/i) || (/runtime/i) )
e = new Error("A CodeMirror inside a P-style element does not work in Internet Explorer. (innerHTML bug)");
throw e;
}

Change the p in the outer layer of textarea to div, and it is normal:
Copy the codeThe code is as follows:

<div style="margin-top:0;">
<asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Height="450" Width="98%"></asp:TextBox>
</div>