Eric Belair
Eric Belair

Reputation: 10702

Why is CKEditor throwing a javascript error when I click or type in the text area?

CKEditor 4.2.1 (and 4.1.2) is randomly (doesn't happen every time) throwing a JavaScript error when performing very basic/simply interactions, like clicking in the editing area and/or typing in the editing area.

Here's my HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>My Page</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script
        type="text/javascript"
        src="/assets/js/ckeditor_4.2.1_full/ckeditor.js"></script>
    <script type="text/javascript">
        $(function(){
            CKEDITOR.replace('my_text');
        });
    </script>
</head>
<body>
    <form method="post">
        <textarea name="my_text">dfagasdf sdf<br /><br />dasf asdf</textarea>
    </form>
</body>
</html>

When clicking or typing into the editing area I see multiple errors in my console:

IE9 Console

Upvotes: 2

Views: 1491

Answers (1)

Reinmar
Reinmar

Reputation: 22023

Have you switched Document Mode to Quirks manually? This may be a reason (although CKEditor is supposed to work in QM and I know it does). Second thing - wrap <textarea> with <fieldset> or <p>. I've seen that it makes problems from time to time (and it's also incorrect to have textarea directly in form).

Edit: The page is running in Quirks Mode, because you've got incorrect DOCTYPE. You should have:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">

Instead of:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

After fixing this, IE stops throwing this error.

PS. You shouldn't also use ISO-8859-1 encoding, which is poor and may lead to issues. Use UTF-8 instead.

Upvotes: 3

Related Questions