I would like to have a button elsewhere on my page that runs the same method that clicking the "Preview" button does in the CKEditor toolbar. I'm using jquery so it would be something like this:
$('#previewButton').click( function () {
$('#editor1').ckEditorGet().Preview();
});
Any ideas how I could accomplish this? I pored over the API documentation but can't find a word on it.
Cheers
Alternatively you can get the editor contents with $('#editor1').val()
, and display it the way you prefer. This example uses a popup window:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="ckeditor/adapters/jquery.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$('#previewButton').click( function () {
var contents = $('#editor1').val();
var mywin = window.open("", "ckeditor_preview", "location=0,status=0,scrollbars=0,width=500,height=500");
$(mywin.document.body).html(contents);
});
$('#editor1').ckeditor();
});
</script>
<textarea id="editor1" cols="5" rows="5">
Contents...
</textarea>
<button id="previewButton">Preview</button>