简体   繁体   English

ck编辑器 - 服务器预览?

[英]ck editor - server preview?

如何获取ckeditor的预览按钮将内容发送到服务器,以便在单击预览时在自定义页面中显示?

We're doing something like this except that we have a preview link on the page that loads the editor. 我们正在做这样的事情,除了我们在页面上有一个加载编辑器的预览链接。 The approach could be used for a button within the editor, but it requires additional coding (I'll outline that approach at the bottom). 该方法可用于编辑器中的按钮,但它需要额外的编码(我将在底部概述该方法)。

The preview link looks something like this: 预览链接看起来像这样:

<a href="#" onclick="return doPreview();">Preview the page</a>

We have the doPreview function: 我们有doPreview功能:

function doPreview() {
var hiddenForm = document.forms[ 'hidden_form' ];

// TextareaId is the id of the textarea being replaced with CKEditor (the instance name)
hiddenForm.elements[ 'preview_content' ].value = CKEDITOR.instances.TextareaId.getData();

// "myform" is the active form that contains the textarea replaced by CKEditor.
var liveForm = document.forms[ 'myform' ];
if ( ! liveForm ) {
  alert( 'Error finding "myform" form.' );
  return false;
}

hiddenForm.submit();

return true;

} }

Finally, there's a form with hidden fields (hiddenForm): 最后,有一个隐藏字段的表单(hiddenForm):

<form name="hiddenForm" action="HTTP://www.yoursite.com/preview_template" method="POST" target="_blank">
  <input type="hidden" name="preview_content" value="" />
</form>

So, the link is clicked and the doPreview function is called. 因此,单击链接并调用doPreview函数。
The function grabs the content from CKEditor and assigns it to a hidden field in the hidden form. 该函数从CKEditor中获取内容并将其分配给隐藏表单中的隐藏字段。
Then the function submits the hidden form. 然后该函数提交隐藏的表单。
The hidden form is posted and the preview template is loaded in a new window. 发布隐藏的表单,并在新窗口中加载预览模板。
The content area of the preview template is populated with $_POST['preview_content'] (the content data from the editor). 预览模板的内容区域填充了$ _POST ['preview_content'](来自编辑器的内容数据)。

You can modify to contain any variables you need to post. 您可以修改以包含您需要发布的任何变量。


To do this by clicking a button within CKEditor: 要通过单击CKEditor中的按钮来执行此操作:
You could create a custom plugin. 您可以创建自定义插件。 There's a tutorial section with easy instructions for creating a plugin here: 这里有一个教程部分,其中包含有关创建插件的简单说明:
http://docs.cksource.com/CKEditor_3.x/Tutorials http://docs.cksource.com/CKEditor_3.x/Tutorials

The plugin could work with a hidden form on the main page again, you'll need to call the parent window from your plugin function. 该插件可以再次使用主页上的隐藏表单,您需要从插件函数调用父窗口。

Or, you could compose the form with JavaScript within your plugin and submit it from there. 或者,您可以在插件中使用JavaScript编写表单并从那里提交。

Note: You can disable the default preview functionality using this setting: 注意:您可以使用此设置禁用默认预览功能:

config.removePlugins = 'preview';

Be Well, Joe 好吧,乔

You can get a plugin ready to work here: http://alfonsoml.blogspot.com/2011/08/serverpreview-plugin-for-ckeditor.html 您可以在此处获得准备好的插件: http//alfonsoml.blogspot.com/2011/08/serverpreview-plugin-for-ckeditor.html

You just have to configure the page that you want to use for the preview and it will replace the default Preview button. 您只需配置要用于预览的页面,它将替换默认的“预览”按钮。 Additional options are explained in the included documentation. 附带的文档中介绍了其他选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM