javascript - CKEditor insert HTML into textarea - Stack Overflow

I'm trying to insert text into CKEditor using javascript. I have currently got this script:functio

I'm trying to insert text into CKEditor using javascript. I have currently got this script:

function quote_<?php echo $row['pid']; ?>() {
        var stringContent = $(".content_<?php echo $row['pid']; ?>").html();
         $("#wysiwyg").val("[quote=<?php echo $row['author']; ?>]" + stringContent + "[/quote]");
         CKEDITOR.instances.wysiwyg.insertHtml('[quote=<?php echo $row['author']; ?>]' + stringContent + '[/quote]');
}

<textarea name="message" style="width:100%" tabindex="3" rows="10" id="wysiwyg">
</textarea>

HTML is not being inserted into the instance 'wysiwyg', so I can't get this to work.

Any ideas?

I'm trying to insert text into CKEditor using javascript. I have currently got this script:

function quote_<?php echo $row['pid']; ?>() {
        var stringContent = $(".content_<?php echo $row['pid']; ?>").html();
         $("#wysiwyg").val("[quote=<?php echo $row['author']; ?>]" + stringContent + "[/quote]");
         CKEDITOR.instances.wysiwyg.insertHtml('[quote=<?php echo $row['author']; ?>]' + stringContent + '[/quote]');
}

<textarea name="message" style="width:100%" tabindex="3" rows="10" id="wysiwyg">
</textarea>

HTML is not being inserted into the instance 'wysiwyg', so I can't get this to work.

Any ideas?

Share Improve this question asked Apr 2, 2012 at 17:50 bearbear 11.6k26 gold badges81 silver badges132 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

This row:

CKEDITOR.instances.wysiwyg.insertHtml('[quote={$row['author']}]' + stringContent + '[/quote]');

the single quotes around 'author' are not escaped. Try:

CKEDITOR.instances.wysiwyg.insertHtml("[quote={$row['author']}]" + stringContent + "[/quote]");

This worked for me:

CKEDITOR.instances.TEXTATEA_ID.insertHtml('<p> html here. </p>');

You can always embed your javascript code into a .php file, as it follows:

<?php

echo <<<JS

<script type='text/javascript'>
    function quote_{$row['pid']}() {
        var stringContent = $(".content_{$row['pid']}").html();
            $("#wysiwyg").val("[quote={$row['author']}]" + stringContent + "[/quote]");
        CKEDITOR.instances.wysiwyg.insertHtml('[quote={$row['author']}]' + stringContent + '[/quote]');
}
</script>
    <textarea name="message" style="width:100%" tabindex="3" rows="10" id="wysiwyg">
    </textarea>
JS;
?>

Also, you can alternatively use php files in which you keep pure (X)HTML markup, but when you e to the point where you would normally echo, just do that:

var stringContent = $(".content_"+<?= $row['pid']; ?>).html();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742324699a4422513.html

相关推荐

  • javascript - CKEditor insert HTML into textarea - Stack Overflow

    I'm trying to insert text into CKEditor using javascript. I have currently got this script:functio

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信