ck 编辑器 - 服务器预览?

发布于 2024-10-21 06:33:28 字数 58 浏览 5 评论 0原文

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

How would I go about getting ckeditor's preview button to send the content to the server so I can show it in a custom page when preview is clicked?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对不⑦ 2024-10-28 06:33:28

我们正在做类似的事情,只不过我们在加载编辑器的页面上有一个预览链接。该方法可用于编辑器中的按钮,但它需要额外的编码(我将在底部概述该方法)。

预览链接看起来像这样:

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

我们有 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;

}

最后,有一个带有隐藏字段的表单 (hiddenForm):

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

因此,单击该链接并调用 doPreview 函数。
该函数从 CKEditor 中获取内容并将其分配给隐藏表单中的隐藏字段。
然后该函数提交隐藏表单。
隐藏的表单已发布,预览模板已在新窗口中加载。
预览模板的内容区域由 $_POST['preview_content'](来自编辑器的内容数据)填充。

您可以修改以包含需要发布的任何变量。


要通过单击 CKEditor 中的按钮来执行此操作:
您可以创建一个自定义插件。这里有一个教程部分,其中包含创建插件的简单说明:
http://docs.cksource.com/CKEditor_3.x/Tutorials

该插件可以工作再次在主页上使用隐藏表单,您需要从插件函数中调用父窗口。

或者,您可以在插件中使用 JavaScript 编写表单并从那里提交。

注意:您可以使用此设置禁用默认预览功能:

config.removePlugins = 'preview';

Be Well,

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:

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):

<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.
The function grabs the content from CKEditor and assigns it to a hidden field in the hidden form.
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).

You can modify to contain any variables you need to post.


To do this by clicking a button within 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

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.

Note: You can disable the default preview functionality using this setting:

config.removePlugins = 'preview';

Be Well,
Joe

鲜血染红嫁衣 2024-10-28 06:33:28

您可以在这里准备一个插件: http://alfonsoml .blogspot.com/2011/08/serverpreview-plugin-for-ckeditor.html

您只需配置要用于预览的页面,它将替换默认的预览按钮。其他选项在随附的文档中进行了解释。

You can get a plugin ready to work here: 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文