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 badges3 Answers
Reset to default 2This 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
评论列表(0条)