最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CKEditor insert HTML into textarea - Stack Overflow

programmeradmin2浏览0评论

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();
发布评论

评论列表(0)

  1. 暂无评论