duankangpazhuo0347 2011-03-07 21:42
浏览 54
已采纳

ck编辑器 - 服务器预览?

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?

  • 写回答

2条回答 默认 最新

  • dongwen9947 2011-09-04 00:24
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch